Empty Tables

  • Thread starter Thread starter Url Onz
  • Start date Start date
UO> Is there any T-SQL that will find an empty table
UO> or which tables have records?


along these lines:

declare c cursor for
select name from sysobjects where xtype='U'
open c

Fetchnext:
fetch next C into @tname
<if eof then leave>
declare @sql nvarchar(50)
set @sql='select @i=count(*) from ' + @tname

declare @i int
exec sp_executesql @sql,N'@i int output',@i output

if @i=0 then @tname is empty
goto fetchnext


Vadim
 
Back
Top