Retrieving all identity columns in a database in SQL Server

We can retrieve the identity for all tables in a database by using the below query:

SELECT  
  TABLE_NAME
, COLUMN_NAME
, IDENT_SEED(TABLE_NAME) AS "Identity Seed"
, IDENT_INCR(TABLE_NAME) AS "Identity Increment"
, COLUMN_DEFAULT
, DATA_TYPE
, IS_NULLABLE
, ORDINAL_POSITION
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
  AND TABLE_NAME != 'sysdiagrams'
ORDER by TABLE_NAME
  • Recent Posts

    • 652,008 hits
  • Join 43 other subscribers
  • Archives

  • Categories

  • April 2024
    M T W T F S S
    1234567
    891011121314
    15161718192021
    22232425262728
    2930