Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem adding a new column with constraint
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01327737
Message ID:
01329014
Vues:
18
>>>I now tried the original suggestion.
>>
>>Did your original suggestion work?
>
>For me it is a little backward, but that works:
>
>IF NOT EXISTS(SELECT column_name
>                     FROM INFORMATION_SCHEMA.COLUMNS
>              WHERE TABLE_NAME = N'Volunteers' and COLUMN_NAME = N'IsActive')
>   BEGIN
>        alter table Volunteers add IsActive bit NULL CONSTRAINT [DF_Volunteers_IsActive] DEFAULT (1)
>        EXEC sp_executesql N'UPDATE Volunteers SET IsActive = 1'
>   END
> SELECT * FROM Volunteers
>
And if you switch (first line with EXEC) and second regular UPDATE, does it still work?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform