没有内置的过程可以完成此 *** 作,但是您可以使用information_schema视图中的信息来构建自己的过程。
基于表的示例
Create Proc dropFK(@TableName sysname)asBeginDeclare @FK sysnameDeclare @SQL nvarchar(4000)Declare crsFK cursor forselect tu.Constraint_Name from information_schema.constraint_table_usage TULEFT JOIN SYSOBJECTS SO ON TU.Constraint_NAME = SO.NAMEwhere xtype = 'F'and Table_Name = @TableNameopen crsFKfetch next from crsFK into @FKWhile (@@Fetch_Status = 0)Begin Set @SQL = 'Alter table ' + @TableName + ' Drop Constraint ' + @FK Print 'Dropping ' + @FK exec sp_executesql @SQL fetch next from crsFK into @FKEndClose crsFKDeallocate crsFKEnd
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)