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 2005 Forums
 Transact-SQL (2005)
 with out using count(*) function

Author  Topic 

js.reddy
Yak Posting Veteran

80 Posts

Posted - 2008-05-06 : 05:37:33
How can know I how may records are there in a table with out using count(*)

Regards
Reddy

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-06 : 05:44:16
[code]select sum(1) from table[/code]

OR

[code]SELECT rows FROM sysindexes WHERE id = OBJECT_ID('Sometable') AND indid < 2[/code]


Note: Second alternative may not give accurate results.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

js.reddy
Yak Posting Veteran

80 Posts

Posted - 2008-05-06 : 05:45:56
Thanks

quote:
Originally posted by harsh_athalye

select sum(1) from table


OR

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



Note: Second alternative may not give accurate results.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-08 : 10:02:41
quote:
Originally posted by js.reddy

How can know I how may records are there in a table with out using count(*)

Regards
Reddy


http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/02/different-ways-to-count-rows-from-a-table.aspx

Madhivanan

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

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-05-09 : 00:35:23
Why? Count(*) is the proper way
Go to Top of Page
   

- Advertisement -