Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select count(*) from table

Author  Topic 

shawnrusin
Starting Member

2 Posts

Posted - 2004-08-10 : 14:14:59
I need to do a
select count(*) from table
but I want my table name to show up too with my returnd rows
so if I do
select count(*) from table
i get
5677 rows
but i want
table 5677 rows or 5677 table

so im looking for some thing like

select count(*) from table1 and show table1 name
union all
select count(*) from table2 and show table2 name
union all
select count(*) from table3 and show table3 name
---------------------------------------------------------
5677 : table1
56 : table2
777 : table3
---------------------------------------------------------
3 rows in set (0.00) sec


Shawn Rusin
MCSE/MCDBA

ffoiii
Starting Member

12 Posts

Posted - 2004-08-10 : 14:42:25
select count(*), 'Table1' from Table1 union all
select count(*), 'Table2' from Table2 union all
select count(*), 'Table3' from Table3


ffoiii
Go to Top of Page

Pat Phelan
Posting Yak Master

187 Posts

Posted - 2004-08-10 : 16:28:38
This is only good after you update the statistics, but you could use:
DBCC UPDATEUSAGE (0) WITH COUNT_ROWS

SELECT rows, Object_Name(id)
FROM dbo.sysindexes
WHERE indid IN (0, 1)
-PatP
Go to Top of Page

shawnrusin
Starting Member

2 Posts

Posted - 2004-08-10 : 17:06:59
thanks that works for me!

Shawn Rusin
MCSE/MCDBA
Go to Top of Page
   

- Advertisement -