Top Menu

Search This Blog

AUTO INCREMENT or IDENTITY

The primary key field to be created automatically every time a new record is inserted.

CREATE TABLE CANDIDATE
 (
   CandidateId int IDENTITY(1,1) PRIMARY KEY,
   CandidateNumber int NOT NULL UNIQUE,
   LastName varchar(50) NOT NULL,
   FirstName varchar(50) NOT NULL,
   PostCode int NULL,
   Address varchar(50) NULL,
   Phone varchar(50) NULL,
)

You see, we use the IDENTITY() for this. IDENTITY(1,1) means the first value will be 1 and then it will increment by 1.

Set IDENTITY(1,1) in the MS-SQL Server Designer Tools:

Click on the column in the MS-SQL designer Tool and go into the Column Properties window.


Post a Comment

Designed by OddThemes | Distributed By Gooyaabi Templates