How to get list of all tables that has identity columns

前端 未结 5 791
小蘑菇
小蘑菇 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:38

          select COLUMN_NAME, TABLE_NAME
          from INFORMATION_SCHEMA.COLUMNS
           where TABLE_SCHEMA = 'dbo'
           and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
           order by TABLE_NAME
    

提交回复
热议问题