Sheen Space

Get table row count – the fast way

leave a comment »


How to get row count of a table in SQL Server quickly? Easist way, of course, is “SELECT COUNT(*) FROM <Table Name>”, most of you would say. However, there is another way, even easier and faster, that is “sp_spaceused <Table Name>”. It is shorter, and more importantly, it returns instantaneously when you try to get information of a huge table (millions of lines).

Experiment on a table with 2.8 million rows shows that time spent with COUNT(*) method is 3 seconds. Actual time taken is dependent on your hardware environment.

MSDN link: http://msdn.microsoft.com/en-us/library/ms188776.aspx

A good article explaining how it works: http://www.sqlservercentral.com/articles/T-SQL/67624/

Advertisements

Written by Ying

04/10/2012 at 09:18

Posted in Technology

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: