1

I need all three fields in my table to be null at once, or all were not null. How to do it? Thanks.

1 Answer 1

2

You need a check constraint

alter table your_table
   add constraint check_nulls
   check (num_nonnulls(col1, col2, col3) in (0,3));

num_nonnulls counts the number of not-null values passed to it. Your requirement is that either all of them are null (result = 0) or all of them are not null (result = 3)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.