RJP Software Blog

.Net info and code snippets

Archive for the ‘SQL Server’ Category

SQL Script – Dropping Foreign Keys

without comments

I stumbled across the following script today which generates the SQL for dropping foreign keys:

SELECT 'ALTER TABLE ' + OBJECT_NAME(parent_object_id) +
   ' DROP CONSTRAINT ' + name FROM sys.foreign_keys
WHERE
   referenced_object_id in (object_id('TableName1'), object_id('TableName2'),
      object_id('TableName3'))

Written by Rich

February 15th, 2012 at 3:41 pm

Posted in SQL Server