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
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)