1

I need to have a list that I can identify in my entire database

SET IDENTITY_INSERT ON

Thank you and thank you for helping me.

5
  • 1
    Closest I found is this: How do you check if IDENTITY_INSERT is set to ON or OFF in SQL Server? and Set IDENTITY_INSERT OFF for all tables. The first answer says that IDENTITY_INSERT is set per session, and will be OFF for a new session, so you don't really have to check it - you probably know if you set it to ON on the same session, or you can create a new session. Commented Jun 19, 2018 at 5:03
  • I accept this too, but I have to be sure to list and give it back. Thank you in any case. Commented Jun 19, 2018 at 5:24
  • 1
    Your entire question seems to be a single statement and not actually a question. I have no idea what you're actually asking about Commented Jun 19, 2018 at 6:14
  • Nice trick with try and catch here Commented Jun 19, 2018 at 6:16
  • Thank you very much. This page is a great help Commented Jun 19, 2018 at 7:37

1 Answer 1

0

I think you need this:

SELECT   'SET IDENTITY_INSERT ' +OBJECT_NAME(OBJECT_ID)+ '  ON' 
FROM SYS.IDENTITY_COLUMNS 
WHERE OBJECT_NAME(OBJECT_ID) not like 'sqlagent_%'
AND OBJECT_NAME(OBJECT_ID) not like 'queue_messages%'

EDIT:

SELECT 'SET IDENTITY_INSERT ' +OBJECT_NAME(OBJECT_ID)+ '  ON;'+'SET IDENTITY_INSERT ' +OBJECT_NAME(OBJECT_ID)+ '  OFF;' 
FROM SYS.IDENTITY_COLUMNS 
WHERE OBJECT_NAME(OBJECT_ID) not like 'sqlagent_%'
AND OBJECT_NAME(OBJECT_ID) not like 'queue_messages%'
Sign up to request clarification or add additional context in comments.

2 Comments

The thing that actually does this is that I can identity I'll turn it on. That's fine thanks and grateful.
If you want both statement together then you can check EDIT part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.