is there any difference between the follow exemples?
ProjNum int
CONSTRAINT nn_ProjNum NOT NULL
CONSTRAINT C_ProjNum CHECK (ProjNum >= 10)
and
ProjNum int NOT NULL
CHECK (ProjNum >= 10)
Thanks.
is there any difference between the follow exemples?
ProjNum int
CONSTRAINT nn_ProjNum NOT NULL
CONSTRAINT C_ProjNum CHECK (ProjNum >= 10)
and
ProjNum int NOT NULL
CHECK (ProjNum >= 10)
Thanks.
There is no difference in SQL Server between those two statements. Each results in NOT NULL column (not a constraint) with a single check constraint. The only difference is that second one creates a system-named check constraint, something like 'CK__t__ProjNum__4AB81AF0'.
Both are same.
In my understanding ,CONSTRAINT CHECK can be define when you add new columns.
ALTER TABLE dbo.DocExc
ADD ColumnD int NULL
CONSTRAINT CHK_ColumnD_DocExc
CHECK (ColumnD > 10 AND ColumnD < 50);
GO
Also user can provide own constraint name.
But if we have to put check in existing column then
ALTER TABLE dbo.DocExc
ADD CHECK (ExistsColumn > 10 AND ExistsColumn < 50);
GO
system will provide constraint name here.