SQL Redundant NOT NULL Constraint

When I add some restrictions, for example:

create table Test( IDTest int primary key, Credit int not null constraint Credit check (Credit >= 0) ); 

In this case, the not null in Credit redundancy is absent, since I add a restriction that Credit should be greater than 0?

+6
source share
1 answer

No, this is not redundant.

A CHECK constraint takes on value if the condition is not FALSE , so it is TRUE or UNKNOWN .

If you enable Nulls in your column, then NULL >= 0 will evaluate to UNKNOWN and the test will pass.

+8
source

Source: https://habr.com/ru/post/909935/


All Articles