kalls
kalls

Reputation: 2865

Checking for Constraint

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

Answers (1)

gbn
gbn

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

Related Questions