Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

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.



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