语言吧

<tfoot draggable='sEl'></tfoot>

MSSQL删除外键约束

使用如下SQL语句查询出表中外键约束名称:

select object_name(B.referenced_object_id)  当前表,

a.name as 约束名,

object_name(b.parent_object_id) as 外键表,

d.name as 外键列,

object_name(b.referenced_object_id) as 主健表,

c.name as 主键列

from sys.foreign_keys A

inner join sys.foreign_key_columns B on A.object_id=b.constraint_object_id

inner join sys.columns C on B.parent_object_id=C.object_id and B.parent_column_id=C.column_id

inner join sys.columns D on B.referenced_object_id=d.object_id and B.referenced_column_id=D.column_id

where object_name(B.referenced_object_id)='需要查询的表名';

执行如下SQL语句删除即可。

alter table 表名 drop constraint 外键约束名


查看更多关于MSSQL删除外键约束的详细内容...

  阅读:1690次
  阅读:1690次