SQL Identity or AUTO INCREMENT a Field in SQL Server:-
Auto-increment allows a unique number to be generated when a new record is inserted into a table. For this we can use IDENTITY keyword.
Example:-
In the above table tblDetail we can pass values for only three colums----->>Name,Email and Address. We did not give value for Id column. The Id column value will insert automatically.
Example:-
CREATE TABLE tblDetail ( ID int IDENTITY(1,1) PRIMARY KEY, Name varchar(255) NOT NULL, Email nvarchar(200), Address varchar(255), ) -------Insert some record in tblDetail table-------- INSERT INTO tblDetail VALUES('Santosh kumar','sk@gmail.com','A-90') INSERT INTO tblDetail VALUES('Arun kumar','a@gmail.com','H-920') INSERT INTO tblDetail VALUES('Mala sharma','ms@gmail.com','Y-50') INSERT INTO tblDetail VALUES('Megha Gupta','mg@gmail.com','D-0213') INSERT INTO tblDetail VALUES('Kapil sharm','kp@gmail.com','P-205')
In the above table tblDetail we can pass values for only three colums----->>Name,Email and Address. We did not give value for Id column. The Id column value will insert automatically.