I want to create a query to return all table name in my SQL database that ha
s
more than 0 records how can I do that ?
Thanks
FREDTry,
use northwind
go
create table #t (
tname sysname,
rcnt int
)
declare @.tn sysname
declare @.sql nvarchar(4000)
declare my_cursor cursor local fast_forward
for
select
quotename(table_schema) + '.' + quotename(table_name)
from
information_schema.tables
where
objectproperty(object_id(quotename(table
_schema) + '.' +
quotename(table_name)), 'IsUserTable') = 1
and objectproperty(object_id(quotename(table
_schema) + '.' +
quotename(table_name)), 'IsMSShipped') = 0
open my_cursor
while 1 = 1
begin
fetch next from my_cursor into @.tn
if @.@.error != 0 or @.@.fetch_status != 0 break
set @.sql = N'select ''' + @.tn + N''', count(*) from ' + @.tn
insert into #t
exec sp_executesql @.sql
end
close my_cursor
deallocate my_cursor
select
*
from
#t
where
rcnt > 0
drop table #t
go
AMB
"FRED" wrote:
> I want to create a query to return all table name in my SQL database that
has
> more than 0 records how can I do that ?
> Thanks
> FRED
>|||Is this useful for you?
select object_name(si.id), rows
from sysindexes si
where si.id = (select object_id(so.name) from sysobjects so where so.type =
'u' and si.id = so.id)
and si.indid < 2
and si.rows > 0
order by 1
"FRED" <FRED@.discussions.microsoft.com> wrote in message
news:7BAC0DB0-2BA9-436F-8105-FCC395631E1A@.microsoft.com...
> I want to create a query to return all table name in my SQL database that
has
> more than 0 records how can I do that ?
> Thanks
> FRED
>|||My problem is solved
Thanks
FRED
"Armando Prato" wrote:
> Is this useful for you?
> select object_name(si.id), rows
> from sysindexes si
> where si.id = (select object_id(so.name) from sysobjects so where so.type
=
> 'u' and si.id = so.id)
> and si.indid < 2
> and si.rows > 0
> order by 1
> "FRED" <FRED@.discussions.microsoft.com> wrote in message
> news:7BAC0DB0-2BA9-436F-8105-FCC395631E1A@.microsoft.com...
> has
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment