database - Delete query in sqlite for child tables -


i have 3 tables, employee, department , electronics tables.

electronics table child table department table , department table child table employee table.

i want delete 1 record in employee table e_id=2 ( primary key) foreign key in department table (e_id foreign key , dept_id primary key) , dept_id foreign key in electronics table.

first want delete related records in electronics table department table , employee table.

please guide me how it.

you can read more foreign key support in sqlite here: http://www.sqlite.org/foreignkeys.html

but should able turn on:

sqlite> pragma foreign_keys = on; 

and setup database schema deletes cascading:

-- database schema create table employee(   e_id    integer primary key,    name    text ); create table department(   dept_id     integer primary key,   name   text,    e_id integer references employee(e_id) on delete cascade ); create table electronics(   elec_id     integer primary key,   name   text,    dept_id integer references department(dept_id) on delete cascade ); 

with in place , data in tables:

delete employee e_id = 2; 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -