DECLARE @Cmd NVARCHAR(MAX) SET @Cmd = CAST(( SELECT 'SET IDENTITY_INSERT ' + QUOTENAME(OBJECT_SCHEMA_NAME([t].[object_id])) + '.' + QUOTENAME([t].[name]) + ' OFF;' + CHAR(10) FROM [sys].[columns] [c] INNER JOIN [sys].[tables] [t] ON [t].[object_id] = [c].[object_id] WHERE [c].[is_identity] = 1 ORDER BY 1 FOR XML PATH('') ) AS NVARCHAR(MAX)); PRINT @Cmd EXEC [sys].[sp_executesql] @Cmd GO