Reputation: 28740
i am new to this topic. i want something like this.
i have two tables in my sqliteDatabase one is master and another is child. Now if i delete a record from master suppose i delete a row from master where id=5, then all the records from the child table whose id = 5 deleted automatically. I don't know how to create triggers and how to apply foreign key constraints so someone please tell me a way to do this in sqlite3 Manager of firefox. Thanks
Upvotes: 0
Views: 1789
Reputation: 55594
You don't need a trigger for that, your foreign key will do that if you define ON DELETE CASCADE
:
CREATE TABLE child(
id INTEGER,
some_info TEXT,
master_id INTEGER,
FOREIGN KEY(master_id) REFERENCES master(id) ON DELETE CASCADE
);
See documentation about foreign keys.
EDIT:
If you really need to do it using a trigger, have a look at Foreing Key Triggers.
Upvotes: 3
Reputation: 129539
This page should help: http://justatheory.com/computers/databases/sqlite/foreign_key_triggers.html
This is a general trigger reference for SQLite
Upvotes: 0