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.
| 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(*). |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-06-30 : 10:23:42
|
| and make sure you run this before that queryDBCC UPDATEUSAGE('db_name','table_name') WITH COUNT_ROWSto get the correct rowsI wonder why there is no view in the Master database to have this rowcountMadhivananFailing to plan is Planning to fail |
 |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2007-07-03 : 02:30:19
|
| Hi,1.Select count(1) From Table |
 |
|
|
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 seeIt is same as count(*)MadhivananFailing to plan is Planning to fail |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
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 MadhivananFailing to plan is Planning to fail |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
|
|
|