Is there a way to programmatically determine the SET IDENTITY_INSERT xyz ON / OFF settings?

SESSIONPROPERTY returns some of the SET parameters for the session (but not IDENTITY_INSERT).

Are there software settings SET IDENTITY_INSERT xyz ON ?

+4
source share
1 answer

This is not very, but if you cannot find another way:

 BEGIN TRY CREATE TABLE #temp (my_id INT IDENTITY NOT NULL) SET IDENTITY_INSERT #temp ON SET IDENTITY_INSERT #temp OFF DROP TABLE #temp END TRY BEGIN CATCH SELECT ERROR_MESSAGE() DROP TABLE #temp END CATCH 

Then you can parse the result from ERROR_MESSAGE () to find out the name of the table (if any) for which it is set. If I find a better way, I will replace this answer.

+1
source

All Articles