解决外键无法删除问题

SELECT  fk.name ,
        fk.object_id ,
        OBJECT_NAME(fk.parent_object_id) AS referenceTableName
FROM    sys.foreign_keys AS fk
        JOIN sys.objects AS o ON fk.referenced_object_id = o.object_id
WHERE   o.name = 'AppTag';

SELECT
    'ALTER TABLE ' +  OBJECT_SCHEMA_NAME(parent_object_id) +
    '.[' + OBJECT_NAME(parent_object_id) +
    '] DROP CONSTRAINT ' + name
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('AppInfo')


SELECT * 
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('Student')



http://stackoverflow.com/questions/1776079/sql-drop-table-foreign-key-constraint
posted @ 2017-04-26 11:49  天藐水瓶  阅读(436)  评论(0编辑  收藏  举报