1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
1. example create table t_name ( id int not null auto_increment, name varchar(18) default "john", t1_id int foreign key t1(id) references t1(id) on delete action, primary key (id) ); 2. foreign key 对应的t1里面的字段必须与references 对应的 字段一致。 on delete 是表示当删除父表中的记录,子表会对对应的记录执行相应的action; 1>CASCADE 父表与子表 相应删除相关的记录 set null 父表删除相关记录 并不删除相关子表的记录,但对应的字段为null; 3> no action or restrict 无法删除父表的记录
on update 同上
|
近期评论