Q:

reseed sql server identity columns

I reseed identity columns like this: 
EXEC sp_MSforeachtable "DBCC CHECKIDENT ( '?', RESEED, 0)"

Query throws me an error if there's no identity in the table. But I still need to reseed identity for all tables in the database that have an identity. (And do not throw an error if there's no identity)

A:

Are all the tables really empty?
DECLARE @sql NVARCHAR(MAX) = N'';

SELECT @sql = @sql + N'DBCC CHECKIDENT(''' 
    + QUOTENAME(OBJECT_SCHEMA_NAME([object_id]))
    + '.' + QUOTENAME(OBJECT_NAME([object_id])) 
    + ''', RESEED, 0);' + CHAR(13) + CHAR(10)
    FROM sys.columns
    WHERE is_identity = 1;

PRINT @sql;
-- EXEC sp_executesql @sql;

