Sha*_*aaz 8 database sqlite android triggers
我在数据库中有两个表:
现在,当删除或添加第一列的房间号时,我的第二个表也应该更新.我认为这可以用TRIGGER命令,但我不确定如何使用它.
通常我的create database语句是这样的:
private static final String DATABASE_CREATE_PATIENT_ID_TABLE =
"create table " + DATABASE_PATIENT_TABLE +
" (_id integer primary key autoincrement,"
+ "patient_number text not null, room_numbertext not null, " +
"patient_initial text not null);";
Run Code Online (Sandbox Code Playgroud)
现在当房间被删除或添加到第一个表中时,我的第二个表应该更新.
private static final String DATABASE_CREATE_NOTES_ID_TABLE =
"create table " + DATABASE_NOTES_TABLE +
" (_id integer primary key autoincrement," +
" room_number text not null, time_hour text not null, " +
"notes_hour text not null, today_date text not null);";
Run Code Online (Sandbox Code Playgroud)
最初我做的是比较两个表的内容.但是,当数据增加时,这肯定会导致性能问题.所以我偶然发现了TRIGGER的事情.我认为这可以解决我的问题,但我不知道我应该如何使用它.
我通过Android使用SQLite数据库来了解它.
我在另一个问题中用屏幕截图解释了这个问题.请看看它,如果请引导我 新的问题
简单的开始
create trigger simple_trigger1 after insert on database_patient_table begin update database_notes_table; end
create trigger simple_trigger2 after delete on database_patient_table begin update database_notes_table; end
Run Code Online (Sandbox Code Playgroud)
请使用此文档http://www.sqlite.org/lang_createtrigger.html
| 归档时间: |
|
| 查看次数: |
19111 次 |
| 最近记录: |