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
时间: 2024-10-25 07:07:22