Searching for tables without an Identity field

0 comments
If you are migrating (or setting up) a database, sometimes the SQL Server doesn't put the identity columns correctly. This SQL shows all the tables that doesn't have any identity field:
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 NOT EXISTS 
(
  SELECT 1 FROM sys.identity_columns
    WHERE [object_id] = t.[object_id]
);
SQL

Comments


Leave a Comment