Last active
January 10, 2016 02:57
-
-
Save tparton42/43695714d2c4041cd2ce to your computer and use it in GitHub Desktop.
SQL Server method for determining if a specific table constraint exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @constraintName varchar(200); | |
SET @constraintName = 'SomeConstraintName'; | |
IF ( SELECT count(*) FROM sys.objects | |
WHERE type_desc LIKE '%CONSTRAINT' | |
AND OBJECT_NAME(object_id) = @constraintName) <> 0 BEGIN | |
PRINT 'FOUND Constraint: ' + @constraintName; | |
-- Perform some action... | |
END | |
ELSE | |
PRINT 'CANNOT FIND Constraint: ' + @constraintName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment