Monday, March 12, 2012

Row count mismatch

Hello!
When I double click on a table in EM I get 536929 rows. When I do a select
count(*) in the QA, I get 537054 rows. A difference of 125. Why do I get
two different row counts for the same table from two different sources?
Baffled,
SeanEM may pull the record count from sysindexes table or some other meta-source
;
I'm pretty sure it doesn't do a COUNT(*) of the actual table.
"sean sobey" wrote:

> Hello!
> When I double click on a table in EM I get 536929 rows. When I do a selec
t
> count(*) in the QA, I get 537054 rows. A difference of 125. Why do I ge
t
> two different row counts for the same table from two different sources?
> Baffled,
> Sean
>
>|||sean sobey wrote:
> Hello!
> When I double click on a table in EM I get 536929 rows. When I do a
> select count(*) in the QA, I get 537054 rows. A difference of 125.
> Why do I get two different row counts for the same table from two
> different sources? Baffled,
> Sean
SQL Server does not track row counts. You can usually get a pretty good
estiamte of rowcount from sysindexes (indid 0 or 1), but if the index
statistics are out of date, the number could be off. I'm guessing that
SQL EM does not perform a COUNT(*) behind the scenes since it might be a
performance issue on large tables.
Of course, now that I'm readind your post in more detail (coffee just
kicked in), I think what you're saying is that you opened a table in SQL
EM (really bad idea in most cases - but that's another story) and the
rows as reported in the row count column differ from row count you see
in QA with a COUNT(*). Could either be that SQL EM is using sysindexes
to show the estimate (it can't know the total row count until all rows
are pulled back).
Trust the QA results and stay away from using SQL EM for opening tables.
David Gugick
Imceda Software
www.imceda.com|||Hi Sean,
Enterprise manager uses the system stored rpocedure "sp_MStablespace" to get
the rows in a table. Actually this stored procedure reads the rowcnt column
from sysindexes table. If the value is incorrect you could run the command
DBCC UPDATEUSAGE to correct the inconsistency in the sysindexes table.
Usage:-
--
DBCC UPDATEUSAGE ('DBNAME','Tablename')
GO
After that you could see the number of rows returned by enterprise manager
and select Count(*) be same.
Thanks
Hari
SQL Server MVP
"sean sobey" wrote:

> Hello!
> When I double click on a table in EM I get 536929 rows. When I do a selec
t
> count(*) in the QA, I get 537054 rows. A difference of 125. Why do I ge
t
> two different row counts for the same table from two different sources?
> Baffled,
> Sean
>
>|||Thank you everyone for clearing this up.
Sean
"Hari Pra" <HariPra@.discussions.microsoft.com> wrote in message
news:916A584E-4110-4F8C-8073-3082C2F52DF1@.microsoft.com...
> Hi Sean,
> Enterprise manager uses the system stored rpocedure "sp_MStablespace" to
get
> the rows in a table. Actually this stored procedure reads the rowcnt
column
> from sysindexes table. If the value is incorrect you could run the command
> DBCC UPDATEUSAGE to correct the inconsistency in the sysindexes table.
>
> Usage:-
> --
> DBCC UPDATEUSAGE ('DBNAME','Tablename')
> GO
> After that you could see the number of rows returned by enterprise manager
> and select Count(*) be same.
> Thanks
> Hari
> SQL Server MVP
> "sean sobey" wrote:
>
select
get

No comments:

Post a Comment