添加外键,alter table B
语法:alter table 表名 add constraint 外键约束名 foreign key(列名) references 引用外键表(列名)
如:
alter table Stu_PkFk_Sc
add constraint Fk_s
foreign key (sno)
references Stu_PkFk_S(sno)
--cc是外键约束名,不能重复,也不能是int类型(如1,2,3)
add constraint cc
--B表里的需要约束的字段(id)
foreign key (id)
--A表后的(id)可省略
references A (id)