Skip to content

IDENTITY

CREATE TABLE Employees (
ID int IDENTITY(1,1),
name varchar(255)
);
INSERT INTO Employees (name)
VALUES ('John Doe'), ('Jane Doe');
SELECT * FROM Employees;
| ID | name |
|----|-----------|
| 1 | John Doe |
| 2 | Jane Doe |

In the example above, the IDENTITY property is used while creating a table Employees. The IDENTITY property creates an identity column for the table Employees. An identity column in SQL Server is typically used for primary keys. When a new row is added, the ID value is automatically created by incrementing the last ID by 1, as the IDENTITY property is set to (1,1). Hence, when inserting the names ‘John Doe’ and ‘Jane Doe’, the ID(identity column) values are automatically created as 1 and 2 respectively.