1

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.

Dário Santos
  • 13
  • 1
  • 4

2 Answers2

8

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'.

David Browne - Microsoft
  • 49,000
  • 3
  • 53
  • 102
0

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.

KumarHarsh
  • 1,623
  • 11
  • 10