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

后端 未结 13 2047
借酒劲吻你
借酒劲吻你 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:29

    This worked for me using Sql Server 2008:

    USE ;
    GO
    SELECT SCHEMA_NAME(schema_id) AS schema_name
        , t.name AS table_name
        , c.name AS column_name
    FROM sys.tables AS t
    JOIN sys.identity_columns c ON t.object_id = c.object_id
    ORDER BY schema_name, table_name;
    GO
    

提交回复
热议问题