Http://stackoverflow.com/questions/2499332/how-to-check-if-a-constraint-exists-in-sql-server
Easiest-to-check for the existence of a constraint (and then do something such as drop it if it exists) are to use the OBJECT_ID () function ...
if object_id ( dbo.[ Ck_constraintname] ' , ' C ' ) is notnull alter table Dbo.[ tablename] drop constraint ck_constraintname
Object_ID can is used without the second parameter (' C ' for check constraints only) and that could also work, but if your Constraint name matches the name of the other objects in the database to get unexpected results.
if object_id ( dbo.[ Ck_constraintname] ' ) isnot null alter table Dbo.[ tablename] drop constraint ck_constraintname
OBJECT_ID can also is used with other "constraints" such as Foreign key constraints or Primary key constraints, etc. For best results, always include the appropriate object type as the second parameter for the OBJECT_ID function:
Constraint Object Types:
- C = CHECK Constraint
- D = DEFAULT (constraint or stand-alone)
- F = FOREIGN KEY constraint
- PK = PRIMARY KEY constraint
- R = Rule (Old-style, stand-alone)
- UQ = UNIQUE Constraint
Also Note that the schema is often required. The schema of constraints generally takes the schema of the parent table.
Failure to put your constraints (or whatever is checking) in brackets when using the This method may also cause a false n Egative--If your object uses unusual characters (such as A.), the brackets is required.
Database CHECK constraint exists