Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Enterprise
Expertise: Beginner
Oct 16, 2001

A Fast Way to Check if a Table Is Empty


If all you need to know is whether a table is empty, using COUNT(*) is a bad alternative, because if the table is very large, it will take some time to count all the rows. Instead, use a SQL statement like the following:
 
SELECT 'The table is NOT empty' WHERE EXISTS 
(SELECT 1 FROM TheTable)

Since the where-clause uses EXISTS, SQL Server will stop processing as soon as it encounters a row in TheTable, and you will know that TheTable is not empty.
Christoffer Hedgate
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date