Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

GET COUNT(*) from 1 table

By ~sudhirchawla,

IN a scenario where the user would like to retrieve the Count(*) from a table without any condition, in that case this query will work

select count(*) from

'Suppose product is the table,
if the product table is light then its ok but if it contains a huge data, then this query can be used.

select max(rowcnt) from sysindexes where id in (select id from sysobjects where name='product')

What will happen in this case, it will reduce the no. of rows to fetch from database. What happens is whenever a row is updated in the database, the 'rowcnt' field is also updated in the sysindexes table.

Regards

Sudhir Chawla

Total article views: 317 | Views in the last 30 days: 1
 
Related Articles
FORUM

"Select Where In" using a parameter?

select intCol from Tablename where intCol in (@intList)

FORUM

How to select count(*) where count < 4

How to select count(*) where count < 4

FORUM

SELECT statement hangs on certain where conditions

Bizarre issue with certain conditions in where statement cause the select to hang forever

FORUM

OPENROWSET select statement performance -- runs in 4 seconds on test server vs. 3 minutes on production server.

OPENROWSET select statement performance -- runs in 4 seconds on test server vs. 3 minutes on product...

FORUM

Conditional Where Clause

Select how the Where Clause operates

Tags
miscellaneous    
 
Contribute