sql语句设置主外键约束

alter table 外键表名 add constraint 约束名称 foreign key(外键字段)  references 主键表名(约束列名) 


如表A中的Ids是主键,要约束表B中的Aid列,那么语句应该是:

alter table B add constraint A_B_Ids foreign key(Aid)  references A(Ids)

原文地址:https://www.cnblogs.com/gbbwzz/p/7716399.html