When I’m adding some constraints, e.g:
create table Test(
IDTest int primary key,
Credit int not null constraint Credit check (Credit >= 0)
);
In this case isn’t the not null in Credit redundant as I’m adding a constraint that Credit must be higher than 0?
No, it is not redundant.
A
CHECKconstraint accepts a value if the condition is notFALSE, so whether it isTRUEorUNKNOWN.If you allow Nulls in your column, then a
NULL >= 0will evaluate toUNKNOWNand will pass the test.