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
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) )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.