Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / June 2007

Tip: Looking for answers? Try searching our database.

Mismatch between Count(*) and Properties -> Rows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
teddysnips@hotmail.com - 29 Jun 2007 15:28 GMT
I have a client who has reported a discrepancy in their database.  In
their test database a certain report returns 5,333 rows, but in the
production database it returns 5, 332 rows.

I'll get to the bottom of it in due course, but I came across an
oddity.  I wanted to know how many rows there were in a particular
table on both databases so I wrote:

SELECT COUNT(*) AS NumRows FROM Answer

It returned 1,919,456.  However, if I click on the Answer table in
Enterprise Manager and select Properties it tells me that there are
1,919,421 rows.  I've tried doing a refresh but it didn't work.

The thing is that the database is pretty static - in fact there's been
no activity (apart from me examining it) for a couple of days.

Thoughts?

Edward
Roy Harvey - 29 Jun 2007 15:42 GMT
>SELECT COUNT(*) AS NumRows FROM Answer
>
>It returned 1,919,456.  However, if I click on the Answer table in
>Enterprise Manager and select Properties it tells me that there are
>1,919,421 rows.  I've tried doing a refresh but it didn't work.

Those statistics are not always accurate.  To fix them run

DBCC UPDATEUSAGE(0) WITH COUNT_ROWS

Roy Harvey
Beacon Falls, CT
Ed Murphy - 30 Jun 2007 02:53 GMT
>> SELECT COUNT(*) AS NumRows FROM Answer
>>
[quoted text clipped - 5 lines]
>
> DBCC UPDATEUSAGE(0) WITH COUNT_ROWS

Is it COUNT(*) or EM - Properties that is sometimes inaccurate?  Under
what circumstances may it be inaccurate?
Roy Harvey - 30 Jun 2007 03:10 GMT
>>> SELECT COUNT(*) AS NumRows FROM Answer
>>>
[quoted text clipped - 8 lines]
>Is it COUNT(*) or EM - Properties that is sometimes inaccurate?  Under
>what circumstances may it be inaccurate?

Enterprise Manager.  EM gets the count from index information
maintained by the system.  The overhead of keeping the numbers
absolutely accurate at all times would be prohibitive, so the row
count gets out of sync with reality at times.  The same goes for space
allocation, which UPDATEUSAGE also fixes.

SELECT COUNT(*) will always be correct.

Roy Harvey
Beacon Falls, CT
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.