views:

202

answers:

2

Hello all, 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

+1  A: 

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.

Peter Lang
it's not working
Rahul Vyas
look at this linkhttp://www.sqlite.org/cvstrac/wiki?p=ForeignKeyTriggers
Rahul Vyas
can you create a trigger for this?
Rahul Vyas
ok i found my sqlit3 version is 3.4.0 now i have also downloaded mac version of sqlite3(Ver. 3.6.22) now how do i install this?
Rahul Vyas
i have also downloaded http://www.sqlite.org/sqlite-amalgamation-3.6.22.tar.gz(A tarball containing the amalgamation together with an configure script and makefile for building it. This is the recommended source distribution for all Unix and Unix-like platforms.) now how do i install this?
Rahul Vyas
@Rahul Vyas: I don't know how to install on Mac, but have a look at the following page: http://sqlite3.darwinports.com/. If this does not help, please ask another question about how to install it on Mac, as this is not really related to your original question.
Peter Lang
can you create a trigger to achieve the functionality i want?
Rahul Vyas
@Rahul Vyas: See the link in my updated answer. Hope that helps you to create the triggers.
Peter Lang