Skip to content

Instantly share code, notes, and snippets.

@nkigen
Created May 18, 2018 15:17
Show Gist options
  • Save nkigen/b562a834194012d68c152ce17b96a60f to your computer and use it in GitHub Desktop.
Save nkigen/b562a834194012d68c152ce17b96a60f to your computer and use it in GitHub Desktop.

Revisions

  1. nkigen created this gist May 18, 2018.
    8 changes: 8 additions & 0 deletions DropCOnstrainstsTSQL.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    DECLARE @SQL NVARCHAR(MAX) = N'';

    SELECT @SQL += N'
    ALTER TABLE ' + OBJECT_NAME(PARENT_OBJECT_ID) + ' DROP CONSTRAINT ' + OBJECT_NAME(OBJECT_ID) + ';'
    FROM SYS.OBJECTS
    WHERE TYPE_DESC LIKE '%CONSTRAINT' AND OBJECT_NAME(PARENT_OBJECT_ID) = 'Your_TABLE';

    PRINT @SQL