Getting Detailed Information About All Tables with Identity Columns in SQL Server
In this article, I will try to give information about getting detailed information about all tables with Identity columns in SQL Server.
In SQL Server, in some cases, you may want to get detailed information about all tables with an Identity column.
You can easily do this using the code below.
SELECT A.TABLE_CATALOG AS CATALOG, A.TABLE_SCHEMA AS "SCHEMA", A.TABLE_NAME AS "TABLE", B.COLUMN_NAME AS "COLUMN", IDENT_SEED(A.TABLE_NAME) AS Seed, IDENT_INCR(A.TABLE_NAME) AS Increment, IDENT_CURRENT(A.TABLE_NAME) AS Curr_Value, B.DATA_TYPE AS "Type", Type_Limit = CASE LOWER(B.DATA_TYPE) WHEN 'bigint' THEN '9,223,372,036,854,775,807' WHEN 'int' THEN '2,147,483,647' WHEN 'smallint' THEN '32,767' WHEN 'tinyint' THEN '255' WHEN 'decimal' THEN REPLICATE('9', B.NUMERIC_PRECISION) WHEN 'numeric' THEN REPLICATE('9', B.NUMERIC_PRECISION) END FROM INFORMATION_SCHEMA.TABLES A, INFORMATION_SCHEMA.COLUMNS B WHERE A.TABLE_CATALOG = B.TABLE_CATALOG AND A.TABLE_SCHEMA = B.TABLE_SCHEMA AND A.TABLE_NAME = B.TABLE_NAME AND COLUMNPROPERTY(OBJECT_ID(B.TABLE_NAME), B.COLUMN_NAME, 'IsIdentity') = 1 AND OBJECTPROPERTY(OBJECT_ID(A.TABLE_NAME), 'TableHasIdentity') = 1 AND A.TABLE_TYPE = 'BASE TABLE' ORDER BY A.TABLE_SCHEMA, A.TABLE_NAME;
When you run the above code, you will see a result similar to the one below.
As you can see, we have received detailed information about all tables with an Identity column.
Good luck to everyone in business and life.