Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mutually exclusive
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01321368
Message ID:
01321392
Vues:
8
>Hi everybody,
>
>How can I make two bit fields to be mutually exclusive? E.g. I have Approved and OnHold fields and if OnHold = 1 Approved should be 0. If OnHold = 0 Approved still can be 0.
>
>Thanks a lot in advance.

Ok, this is what I wrote, though I don't think it's a good way:
ALTER TABLE [dbo].[Registration]  WITH CHECK ADD  CONSTRAINT [CK_Registration_Approved_OnHold] CHECK  (([Approved]=(1) AND [OnHold]=(1) OR [OnHold]=(1) AND [Approved]=(0) OR [Approved]=(0) AND [OnHold]=(0)))
GO
ALTER TABLE [dbo].[Registration] CHECK CONSTRAINT [CK_Registration_Approved_OnHold]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'If Approved = 1 OnHold should be 0 and vice versa.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Registration', @level2type=N'CONSTRAINT',@level2name=N'CK_Registration_Approved_OnHold'
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