SQL Rowcount table is different from Select Count in SQL Server

I am using Microsoft SQL Server.

I have a table that has been updated to 80 rows.

If I right-click and look at the properties of the table, row will say 10000, but select Count (id) from TableName indicating 10080.

I checked the statistics and they also have a line number of 10080.

Why is there a difference between Rocount properties in properties and Count Count?

Thanks, S

+3
source share
4 answers

This information most likely comes from the sysindexes table (see the documentation) and the information in sysindexes is not guaranteed to be up to date. This is a known fact in SQL Server.

DBCC UPDATEUSAGE .
: http://msdn.microsoft.com/en-us/library/ms188414.aspx

DBCC UPDATEUSAGE , , , . , DBCC UPDATEUSAGE . , NO_INFOMSGS , DBCC UPDATEUSAGE , .

:

DBCC UPDATEUSAGE (0)
+3

. , RDBMS . .

SQL Server 2005

UPDATE STATISTICS dbOwner.yourTableName;

Oracle

UPDATE STATISTICS yourSchema.yourTableName;
+2

SSMS.

+1

.

http://blogs.msdn.com/b/martijnh/archive/2010/07/15/sql-server-how-to-quickly-retrieve-accurate-row-count-for-table.aspx 4 .

.

SELECT COUNT(*) FROM Transactions

SELECT CONVERT(bigint, rows)
FROM sysindexes
WHERE id = OBJECT_ID('Transactions')
AND indid < 2

, ssms gui

SELECT CAST(p.rows AS float)
FROM sys.tables AS tbl
INNER JOIN sys.indexes AS idx ON idx.object_id = tbl.object_id and idx.index_id < 2
INNER JOIN sys.partitions AS p ON p.object_id=CAST(tbl.object_id AS int)
AND p.index_id=idx.index_id
WHERE ((tbl.name=N'Transactions'
AND SCHEMA_NAME(tbl.schema_id)='dbo'))

SELECT SUM (row_count)
FROM sys.dm_db_partition_stats
WHERE object_id=OBJECT_ID('Transactions')   
AND (index_id=0 or index_id=1);

, .

0

Source: https://habr.com/ru/post/1721313/


All Articles