troubleshooting Question

How to create a check constraint to force one of two fields to be null

Avatar of smcintire001
smcintire001Flag for United States of America asked on
Microsoft SQL ServerMySQL ServerSQL
7 Comments1 Solution442 ViewsLast Modified:
I've inherited a database that has several inconsistencies in the data.   I'm trying to work to block some of these using check constraints.  

I have a single table where all values are nullable, but the logic requires that one of two (datetime) columns (at a minimum) be null.   Both can be null, but if one has a date in it, the other cannot have a date in it.    I'm trying to figure out a way to enforce this through constraints.   I am trying to avoid using an indexed view because they're really a pain for me.  I was hoping there was a way to write a check constraint to prevent this.  

Thanks in advance.  
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros