Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem adding a new column with constraint
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Problem adding a new column with constraint
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01327737
Message ID:
01327737
Vues:
62
Hi everybody,

This code
IF NOT EXISTS
(SELECT column_name
FROM information_schema.columns
WHERE table_name = N'AdultInfo' and column_name = N'MaritalStatus')

   BEGIN
	alter table AdultInfo add MaritalStatus char(1) null
	ALTER TABLE [dbo].[AdultInfo]  WITH CHECK ADD  CONSTRAINT [CK_AdultInfo] CHECK  (([MaritalStatus] IS NULL OR ([MaritalStatus] IN ('W','S','D','M'))))
  END
produces an error on the second line (adding CHECK constraint). Perhaps because the field is not added immediatelly?

If I execute the lines one by one it works. So, I guess I may need to add one more test for the existence of the field before the second ALTER TABLE.

Do you see why I'm getting the error and how can I correct the problem?

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform