Thursday, September 8, 2016

Check to see if a restraint exists in T-SQL.

IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =
      OBJECT_ID(N'FK_File_Users'))
   BEGIN
      PRINT 'Dropping FK_File_Users restraint.'
      ALTER TABLE dbo.[FILE] DROP CONSTRAINT FK_File_Users
   END
ELSE
   BEGIN
      PRINT 'FK_File_Users has already been dropped.'
   END

No comments:

Post a Comment