I am curious to know is it possible to create a conditional not null constraint in sql? In otherwords is it possible to create a constraint such that a column B can be null as long column A contains lets say ‘NEW’ but if the contents of column A changes to something else then column B is no longer allowed to be null?
And to extend on that, it is then possible to make it so that column B must be null or empty as long as column A says ‘NEW’?
Thanks All 😀
I am curious to know is it possible to create a conditional not null
Share
This is perfectly fine for CONSTRAINT CHECK. Just do this:
Requirement:
Note the phrase: column B can be null
Solution:
You can simplify it further:
Requirement mutually incompatible to requirement above:
Note the phrase: column B must be null
Could be simplified with this, simpler but might not be as readable as above though: