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
 SQL Server Development (2000)
 Finding Count of table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-06-30 : 07:54:39
Sathish writes "Is there any way to find the number of records in a table with out using count(*) in SQL Server?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-06-30 : 07:56:27
OK, I'm gonna violate my "don't access system tables directly" pontification:

SELECT rows FROM sysindexes WHERE indid<2 AND id=OBJECT_ID('myTable')

Note that this will give you the total number of rows in the table. If you only want rows that meet a certain condition (WHERE col1=1) then you need to use Count(*).
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-30 : 10:23:42
and make sure you run this before that query
DBCC UPDATEUSAGE('db_name','table_name') WITH COUNT_ROWS
to get the correct rows
I wonder why there is no view in the Master database to have this rowcount

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 2007-07-03 : 02:30:19
Hi,

1.Select count(1) From Table


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-03 : 04:08:52
quote:
Originally posted by ranganath

Hi,

1.Select count(1) From Table





Set the execution plan and see
It is same as count(*)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-03 : 04:09:51
But it meets the criteria to not use count(*)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-03 : 04:25:38
Well. If that is the case, there can be n number of ways to get the same

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-03 : 04:31:27
Exactly. The home work assignment was not clear enough about problem statement.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -