Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mutually exclusive
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01321368
Message ID:
01321392
Views:
7
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform