Reputation: 47
I need create a constraint with this condition If column_1 = 'Y' then column_2 is not null. I need make the column_2 not null if column_1 is equal 'Y'. In other cases you can insert or not values in column_2
Upvotes: 2
Views: 500
Reputation: 1269783
You can express this as:
check (column_1 <> 'Y' or column_2 is not null)
Note: This version assumes that column_1
is not NULL
, but the logic can easily be adjusted to handle that.
Or, alternatively:
check (not (column_1 = 'Y' and column_2 is null) )
Upvotes: 1