Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IDENTITY_INSERT status 1

Status
Not open for further replies.

grnzbra

Programmer
Mar 12, 2002
1,273
US
I need to insert values into an identity field, but I don't know what the normal status of IDENTITY_INSERT is for this database. Is there any way to determine the status of IDENTITY_INSERT prior to running the INSERT statement?
 
I don't think there is. When you set identity_insert on, it is only on "for the session". This means that if you disconnect your session and then re-connect, identity_insert will not be on for any of your tables.

Since you are having this problem, I can only assume it's because you attempted to set it on and it failed. Whenever I need to use identity_insert, I always approach it the same way that I use transactions. Every transaction has a definite starting point (begin transaction) and a definite ending point (commit or rollback transaction).

Basically, whenever you set identity_insert on, you should always set it off. This will save you this kind of trouble.



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top