Reputation: 2865
I need to write a SQL script to ensure that a constraint is existing.
If the constraint exists, I will be dropping the constraint. How to achieve this?
Upvotes: 0
Views: 96
Reputation: 432657
IF OBJECT_ID('Schema.constraintname') IS NOT NULL
ALTER TABLE Schema.foo DROP constarintname
You need Schema.constraintname
to correctly resolve schema. You could have 2 PK_foo
objects if you have tables this.foo
and that.foo
Upvotes: 2