I am new to the SQL server world. Hope someone will kindly give me answer
to the following situation. Thanks in advance.
Among many there are 3 columns in a table:
ExemptEmployee (bit, Not Null)
AnnualSalary (Money, Null)
HourlyWage (Money, Null)
If ExemptEmployee is True, then AnnualSalary field must have a value and
HourlyWage field must be Null. If ExemptEmployee is False, then AnnualSalary
field must be Null and HourlyWage field must have a value.
Is there any easy way of enforcing the logic using constraint? If so, how
would write the constraint?
Re: constraint question
I used this:
create table t (
ExemptEmployee bit Not Null,
AnnualSalary Money Null,
HourlyWage Money Null,
check ((ExemptEmployee = 1 and AnnualSalary is not null and HourlyWage is
(ExemptEmployee = 0 and AnnualSalary is null and HourlyWage is not null))
Michael Levy MCDBA, MCSD, MCT
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL