Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of all tables that has identity columns

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

like image 698
Allan Chua Avatar asked Apr 16 '13 18:04

Allan Chua


1 Answers

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] ); 
like image 103
Aaron Bertrand Avatar answered Sep 28 '22 06:09

Aaron Bertrand