2010-12-02 27 views
0

Je dois écrire un script SQL pour m'assurer qu'une contrainte existe.Vérification de la contrainte

Si la contrainte existe, je vais abandonner la contrainte. Comment y parvenir?

Répondre

2
IF OBJECT_ID('Schema.constraintname') IS NOT NULL 
    ALTER TABLE Schema.foo DROP constarintname 

Vous avez besoin de Schema.constraintname pour résoudre correctement le schéma. Vous pouvez avoir 2 PK_foo objets si vous avez des tables this.foo et that.foo