外键约束

来源:互联网 发布:阿里云空间控制面板 编辑:程序博客网 时间:2024/06/01 08:08


数据表某一列是其他数据表中主键,则这一列为外键。
1   2    3    4
q   w    e    r     2外键


2   9
w   m      2主键


create table sub
(daiti tinyint not null,
wujin int not null,
ditie varchar(10) not null);

create table hardware
(wujin int primary key not null,
yingjian char(5) not null);


alter table sub
add constraint fk_wujin(自己定义约束名) foreign key(wujin) references hardware(wujin);

此时删不掉表hardware..

阅读全文
0 0
原创粉丝点击