Does SQL server retain the setting for IDENTITY_INSERT after a session closes

MichaelHorwell-4553 0 Reputation points
2025-12-17T08:48:50.45+00:00

I have set IDENTITY_INSERT ON for a table, does that setting remain after the session ends?

SQL Server Database Engine
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lakshmi Narayana Garikapati 735 Reputation points Microsoft External Staff Moderator
    2025-12-17T12:43:27.8+00:00

    Hi MichaelHorwell-4553,

    Thank you for reaching out to the SQL Forum.- SET IDENTITY_INSERT TableName ON is session‑scoped. That means:

    • It only applies to the current connection.
    • SQL Server allows only one table per session to have IDENTITY_INSERT set to ON.
    • As soon as the session ends (for example, you close the query window or disconnect), the setting is automatically reset to OFF.
    • If you reconnect and want to insert explicit values into the identity column again, you’ll need to re‑run the SET IDENTITY_INSERT command.

    Hope This Helps!!

    Thanks,

    Lakshmi.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.