Is there any way to count tables with no rows in my database with using T-SQL statement?
from khtan @ SQL Server Forums, this is used to drop all empty tables, maybe you could adapt it to output a count?
declare @name varchar(128), @sql nvarchar(2000), @i int
select @name = ''
while @name < (select max(name) from sysobjects where xtype = 'U')
begin
select @name = min(name) from sysobjects where xtype = 'U' and name > @name
select @sql = 'select @i = count(*) from [' + @name + ']'
exec sp_executesql @sql, N'@i int out', @i out
if @i = 0
begin
select @sql = 'drop table [' + @name + ']'
print @sql
-- unmask next to drop the table
-- exec (@sql)
end
end
I don't have SQLServer here but I could take a stab at it if you like.