Consider the following T-SQL code (the code is available along with an ADO.NET version in this GitHub repo https://github.com/PaloMraz/SqlServerReseedSampleApp):
DROP TABLE IF EXISTS __Test;
CREATE TABLE __Test (Id INT IDENTITY NOT NULL PRIMARY KEY);
GO
BEGIN TRAN;
SET IDENTITY_INSERT __Test ON;
INSERT INTO __Test (Id) VALUES (100);
SET IDENTITY_INSERT __Test OFF;
DBCC CHECKIDENT('__Test', RESEED, 1);
ROLLBACK TRAN;
GO
SELECT IDENT_CURRENT('__Test'); -- returns 100 instead of 1
The code does the following:
- Creates a __Test table with IDENTITY column.
- Starts a transaction.
- INSERTs new row overriding the IDENTITY seed value to 100.
- Reseeds the IDENTITY back to 1.
- Rolls back the transaction.
- Queries the current identity.
I have expected, that the current identity value will be back at 1, but instead, it is 100. This means that the transaction rolled back the inserted row and the results of the DBCC CHECKIDENT command, but did not roll back the overridden IDENTITY seed!
Is this the correct behavior? Why?
Thank you for your time!