How do you check if IDENTITY_INSERT is set to ON or OFF in SQL Server?

前端 未结 8 972
暗喜
暗喜 2020-12-09 00:52

I\'ve searched for this, but threads in which it appeared tended to have answers from people who didn\'t understand the question.

Take the following syntax:

<
8条回答
  •  隐瞒了意图╮
    2020-12-09 01:15

    you can also use the ObjectProperty method to determine if a table has an identity:

    DECLARE @MyTableName nvarchar(200)
    SET @MyTableName = 'TestTable'
    SELECT CASE OBJECTPROPERTY(OBJECT_ID(@MyTableName), 'TableHasIdentity') 
    WHEN 1 THEN 'has identity' 
    ELSE 'no identity columns' 
    END as HasIdentity
    

提交回复
热议问题