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:
01328707
Vues:
11
>You get error because the transaction is not committed yet and the new field is not in the table. Try this:
>
>IF NOT EXISTS(SELECT column_name
>                                     FROM information_schema.columns
>                                     WHERE table_name = N'AdultInfo' and column_name = N'MaritalStatus')
>   BEGIN
>        sp_executesql N'alter table AdultInfo add MaritalStatus char(1) null' -- Only to be in other batch
>        ALTER TABLE [dbo].[AdultInfo]  WITH CHECK ADD  CONSTRAINT [CK_AdultInfo] CHECK  (([MaritalStatus] IS NULL OR ([MaritalStatus] IN ('W','S','D','M'))))
>   END
>
Looks like I need to add EXECUTE in front of the statement.
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