How do you determine what SQL Tables have an identity column programmatically

后端 未结 13 2068
借酒劲吻你
借酒劲吻你 2020-11-30 23:44

I want to create a list of columns in SQL Server 2005 that have identity columns and their corresponding table in T-SQL.

Results would be something like:

Tab

13条回答
  •  心在旅途
    2020-12-01 00:25

    Another way (for 2000 / 2005/2012/2014):

    IF ((SELECT OBJECTPROPERTY( OBJECT_ID(N'table_name_here'), 'TableHasIdentity')) = 1)
        PRINT 'Yes'
    ELSE
        PRINT 'No'
    

    NOTE: table_name_here should be schema.table, unless the schema is dbo.

提交回复
热议问题