Why is use IDENTITY() in SQL Server, how to make an auto-incremented table in SQL Server?
Why is use IDENTITY() in SQL Server, how to make an auto-incremented table in SQL Server?
48122-Sep-2021
Updated on 22-Sep-2021
Home / DeveloperSection / Forums / Why is use IDENTITY() in SQL Server, how to make an auto-incremented table in SQL Server?
Why is use IDENTITY() in SQL Server, how to make an auto-incremented table in SQL Server?
Ashutosh Kumar Verma
27-Sep-2021SQL Identity:
Auto Increment allows a unique number which is automatically generated every time a new record is inserted in the table. SQL Auto Increment is mainly used in Primary Field.
Or, we can say that when a new record is inserted in database table then the identity value increased automatically for that record. Often it created as in primary key that I would like to created automatically when a new record is inserted. In other word Identity is called as auto-increment.
Syntax-
Example:
There is database table is created with Identity Constraint in primary as like below,
Now, records is inserted in the above created table,
It you observe that in above SQL statement in which record is insert in database table column ‘stuID’ is not inserted through command, it is automatically generated. So stuID in automatically generated when I insert a new record into that table because ‘stuID’ is defined as Identity.