Search code examples
sqlsql-servert-sqlidentity-column

How to get the list of all tables that have identity columns


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


Solution

  • SELECT 
      [schema] = s.name,
      [table] = t.name
    FROM sys.schemas AS s
    INNER JOIN sys.tables AS t
      ON s.[schema_id] = t.[schema_id]
    WHERE EXISTS 
    (
      SELECT 1 FROM sys.identity_columns
        WHERE [object_id] = t.[object_id]
    );