如何使用触发器的Andr​​oid的SQLite触发器、如何使用、Andr、oid

2023-09-05 07:44:40 作者:大众逗比王/国民女神经

我在数据库中的两个表:

I have two tables in database:

在表中的一个有名字和房间号列 在表中的两个有房号和时间列。

现在,当从第一列中的房号删除或添加,我的第二个表也应该进行更新。我认为这是可能的触发命令,但我真的不知道如何使用它。

Now when the room number from first column is deleted or added, my second table should also be updated. I think this is possible with TRIGGER command, but I am not really sure as how to use it.

通常我创建数据库的语句是这样的:

Generally my create database statement is like this:

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);";

现在房间都删除或第一个表我的第二个表需要更新时添加。

Now when the rooms are deleted or added in the first table my second table should be updated.

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);";

起初,我所做的就是当比较两个表的内容。但是,这肯定会导致性能问题后,当数据将增加。所以,我偶然发现触发的事情。我认为这可以解决我的问题,但我不知道我应该怎样准确地使用它。

Initially I was doing was compare the content of the two tables. But this definitely will lead to performance issue later when data will increase. So I stumbled across TRIGGER thing. I think this can solve my problem, but I don't know how exactly should I use it.

我来了解它使用SQLite数据库与Android 。

我已经解释过这个问题,拍摄的画面在我的另外一个问题。请看看它,如果请您指导我 新问题

推荐答案

简单启动你

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

使用本文档http://www.sqlite.org/lang_createtrigger.html