解决方法
没有内置的过程来完成此操作,但是您可以使用information_schema视图中的信息构建自己的过程.
基于表的示例
Create Proc dropFK(@TableName sysname) as Begin Declare @FK sysname Declare @sql nvarchar(4000) Declare crsFK cursor for select tu.Constraint_Name from information_schema.constraint_table_usage TU LEFT JOIN SYSOBJECTS SO ON TU.Constraint_NAME = SO.NAME where xtype = 'F' and Table_Name = @TableName open crsFK fetch next from crsFK into @FK While (@@Fetch_Status = 0) Begin Set @sql = 'Alter table ' + @TableName + ' Drop Constraint ' + @FK Print 'Dropping ' + @FK exec sp_executesql @sql fetch next from crsFK into @FK End Close crsFK Deallocate crsFK End