IDENTITY is a column property that automatically assigns a sequential numeric value whenever a row is inserted. It eliminates the need to manually supply primary-key values and is commonly used for surrogate keys. In SQL Server, IDENTITY(seed, increment) defines the starting number and the step between numbers; the database guarantees uniqueness within the table but not across tables. Standard SQL introduced IDENTITY columns in SQL:2003 with the syntax GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY, and other platforms implement comparable functionality (e.g., MySQL AUTO_INCREMENT, PostgreSQL SERIAL/IDENTITY). IDENTITY values cannot be updated directly unless IDENTITY_INSERT is set ON, and reseeding requires DBCC CHECKIDENT or ALTER TABLE ALTER COLUMN RESTART WITH in newer standards. Caveats: gaps appear after rollbacks or deletes; only one IDENTITY column is allowed per table in SQL Server; replication and bulk load tools may need NOT FOR REPLICATION to bypass automatic generation.
seed
(numeric) - first value generatedincrement
(numeric) - value added to the previous identity to create the next oneNOT FOR REPLICATION
(flag) - prevents the identity from being incremented during replication or bulk insertGENERATED ALWAYS | BY DEFAULT
(keyword, Standard SQL) - controls whether users may supply their own valueAUTO_INCREMENT, SERIAL, SEQUENCE, PRIMARY KEY, IDENTITY_INSERT, SCOPE_IDENTITY, DBCC CHECKIDENT
SQL Server 6.0 (1995); standardized in SQL:2003
IDENTITY is a table-bound auto-increment property, while SEQUENCE is a standalone object that can serve multiple tables and can be advanced manually.
Temporarily enable IDENTITY_INSERT ON for that table, insert the desired value, then set IDENTITY_INSERT OFF. Only one table per session may have IDENTITY_INSERT ON.
Yes. TRUNCATE TABLE resets the identity seed back to its original starting value unless it was reseeded manually.
If the column is defined as PRIMARY KEY or has a UNIQUE constraint, an index is created. Otherwise, IDENTITY alone does not create an index.