2013-04-08 170 views
-5

我想刪除從那裏記錄存在的所有表與學生佩塔爾·彼得羅夫'相關的所有記錄中的所有表(有三個表)刪除記錄在SQL

+3

請添加表結構,例如數據和哪兒你被卡住。 – 2013-04-08 12:09:27

+0

[delete-a-record-related-with-student-ivan-petrov-from-all-tables-where-re-re]可能的重複(http://stackoverflow.com/questions/15878624/) – 2013-04-08 12:11:43

+0

你想要在提出此問題前2分鐘刪除與* Ivan Petrov相關的所有記錄。 :P http://stackoverflow.com/questions/15878624/delete-a-record-related-with-student-ivan-petrov-from-all-tables-where-such-re – 2013-04-08 12:14:20

回答

0

我猜你應該使用架構中的級聯foreign keys

e.g:

create table students (
id int, 
constraint pk_students primary key (id) 
); 

create table a(
s_id int, 
constraint fk_a_student foreign key (s_id) references students on delete cascade 
); 

create table b(
s_id int, 
constraint fk_b_student foreign key (s_id) references students on delete cascade 
);