首页 > 数据库技术 > 详细

外键删除(T-SQL Drop Foreign Key)

时间:2014-02-22 23:19:10      阅读:695      评论:0      收藏:0      [点我收藏+]

列出某张表相关的 FK Name
select distinct name from sys.objects where object_id in
(   select fk.constraint_object_id from sys.foreign_key_columns as fk
    where fk.referenced_object_id =
        (select object_id from sys.tables where name = ‘TableName‘)
)

列出主外键关系

select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = ‘User‘)
order by TableWithForeignKey, FK_PartNo;

删除外键

alter table Membership drop FK_Membership_Organization

外键删除(T-SQL Drop Foreign Key)

原文:http://www.cnblogs.com/Flyear/p/3560825.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!