Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 316 | 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

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones