Mega Code Archive

 
Categories / MSSQL Tutorial / Constraints
 

Primary Key Constraint

A table's primary key is the primary value that is used to uniquely identify every row in the table. The primary key designation is specified as a constraint on the table. Constraints can be created during the initial CREATE TABLE statement or can be added later with an ALTER TABLE statement. 9> 10> CREATE TABLE MyTable (MyID Int IDENTITY(1,1) NOT NULL CONSTRAINT PK_ID PRIMARY KEY 11>           , Description nVarChar(50) NOT NULL 12>           , Region nVarChar(10) NOT NULL DEFAULT 'PNW' ) 13> GO 1> 2> drop table MyTable; 3> GO 1>