How to get list of all tables that has identity columns

前端 未结 5 790
小蘑菇
小蘑菇 2021-02-04 00:21

I would like to learn how to fetch list of all tables that has identity columns from a MS SQL database.

5条回答
  •  粉色の甜心
    2021-02-04 00:25

    The script below will do:

    SELECT a.name as TableName,
      CASE WHEN b.name IS NULL
        THEN 'No Identity Column'
        ELSE b.name
      END as IdentityColumnName
    FROM sys.tables a
      LEFT JOIN sys.identity_columns b on a.object_id = b.object_id 
    

提交回复
热议问题