语法:
Foreign Key
(column[,...n])
references referenced_table_name[(ref_column[,...n])]
[on delete cascade]
[on update cascade]
注释:
column:列名
referenced_table_name:外键参考的主键表名称
ref_name:外键要参考的表的主键列
on delete:删除级联
on update:更新级联
alter table B add constraint snum
foreign key(snum) references A(snum) on update cascade, delete cascade;
alter table C add constraint snum
foreign key(snum) references A(snum) on delete cascade,delete cascade;
//Then all records these contain snum=1 will be deleted from table A, B and C.
delete from A where snum=1;
//Then all records these contain snum=2 will be updated from table A, B and C.
update A set snum=11 where snum=2;