简体   繁体   中英

SELECT * Returns no rows but, SELECT Count(*) returns non zero value

I run following queries:

a. select * from TABLE_TEMP

The query is executed successfully but, no rows are returned. the returned dataset is empty and contains 0 rows. The execution plan of this query can be downloaded from: Execution Plan Query a

b. select count(*) from TABLE_TEMP

This query is also executed successfully but, it returns some finite value The execution plan of this query can be downloaded from: Execution Plan Query b

Can you provide me any pointers to resolve this issue.

PFB the screenshot: 奇怪的行为

You might be suffering from some sort of corruption in your database. Run DBCC CHECKDB (or DBCC CHECKTABLE ) after familiarising yourself with the documentation . In particular, the section on index checking with respect to database compatibility levels and:

In earlier versions of SQL Server, the values for the per-table and per-index row count and page counts can become incorrect. Under certain circumstances, one or more of these values might even become negative. In SQL Server 2005 and later, these values are always maintained correctly. Therefore, databases that are created on SQL Server 2005 and later should never contain incorrect counts; however, databases that are upgraded to SQL Server 2005 and later might.

Count is Function in SQL it returns Int value ie how many records affected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM