删除sql中所有表中的记录

时间:2013-04-08 12:08:43

标签: sql

我想从存在记录的所有表中删除与学生'Petar Petrov'相关的所有记录(有三个表)

2 个答案:

答案 0 :(得分:0)

如何在外键上使用删除级联?

答案 1 :(得分: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
);