SQL外键约束

1.查询表已有的外键

select name  
from  sys.foreign_key_columns f join sys.objects o on f.constraint_object_id=o.object_id 
where f.parent_object_id=object_id('表名')

2.删除表外键

alter table 表名 drop constraint 外键约束名

3.添加外键

alter table 表名 add constraint 外键约束名 foreign key(列名) references 引用外键表(列名) 
原文地址:https://www.cnblogs.com/lyd2016/p/7453069.html