Say that you’re a table, and you don’t want to refer to any parents or children using foreign keys (and vice versa).
There’s a script for that:
--drop fks coming in and out DECLARE @sql NVARCHAR (max) SET @sql = '' SELECT @sql = @sql + N'ALTER TABLE ' + OBJECT_NAME(parent_object_id) + N' DROP CONSTRAINT ' + name + N'; ' FROM sys.foreign_keys WHERE 'TableName' IN ( OBJECT_NAME(parent_object_id), OBJECT_NAME(referenced_object_id) ) EXEC sp_executesql @sql |
Just remember to replace “TableName” with the name of the table.
Disclaimer: Take care guys!