Empty Tables

V

Vadim Rapp

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top