IDENTITY_INSERT
Example
Section titled “Example”SET IDENTITY_INSERT dbo.YourTable ON;
INSERT INTO dbo.YourTable (ID, Name)VALUES (5, 'Sam');
SET IDENTITY_INSERT dbo.YourTable OFF;Output
Section titled “Output”New entry in YourTable:
| ID | Name |
|---|---|
| 5 | Sam |
Explanation
Section titled “Explanation”In the example provided, the IDENTITY_INSERT property was enabled for YourTable, allowing an explicit value (in this case, ‘5’) to be inserted into the identity column ‘ID’. The name column received the value ‘Sam’. After inserting the data, the IDENTITY_INSERT property was turned off to ensure the SQL Server manages the identity column automatically again.