La siguiente consulta te puede ayudar a conocer el nombre de la tabla y si tiene campo de tipo IDENTITY
. Simplemente es hacer JOIN
a la definición de tablas y columnas con respecto al campo llave object_id
:
SELECT t.name, c.name
FROM sys.tables t
INNER JOIN sys.columns c
ON t.object_id = c.object_id
WHERE c.is_identity = 1
ORDER BY t.name
Para listar con un solo query todos los campos que son IDENTITY
de todas las bases de datos quedaría de la siguiente manera:
DECLARE @sql NVARCHAR(max);
SET @sql = N'select cast(''master'' as sysname) as db_name, t.name collate Latin1_General_CI_AI Tabla, c.name collate Latin1_General_CI_AI Columna, c.is_identity from master.sys.tables t INNER JOIN master.sys.columns c ON t.object_id = c.object_id WHERE c.is_identity = 1';
SELECT @sql = @sql + N' union all select ' + quotename(name, '''') + ', t.name collate Latin1_General_CI_AI, c.name collate Latin1_General_CI_AI object_id, c.is_identity from ' + quotename(name) + N'.sys.tables t INNER JOIN ' + quotename(name) + '.sys.columns c ON t.object_id = c.object_id WHERE c.is_identity = 1'
FROM sys.databases
WHERE database_id > 1
AND STATE = 0
AND user_access = 0
AND name NOT IN (
'tempdb'
,'model'
,'msdb'
)
--PRINT @sql
EXEC sp_executesql @sql;