0

Alternate ways to Count the Number of Records in SQL

Reading Time: 1 minute

In SQL the generic way to count the number records in any SQL database is

SELECT COUNT(*) FROM TableName; 

This works on all the databases but there are other alternates ways to find the number records of a table. Some are much more efficient than generic way. So the below are the query specific to a database

 

Microsoft SQL

SELECT rows FROM sysindexes WHERE id = object_id('TableName') AND indid<2;

 

MySQL

SELECT table_rows FROM information_schema.tables
WHERE table_schema = DATABASE();

Oracle

SELECT num_rows FROM all_tables 
WHERE table_name = 'TABLE_NAME_IN_UPPERCASE';

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.