Wednesday, April 14, 2010

Table Row Count

Many times we need to find out how many rows a particular table has?. Generally Select Count(*) From table query is used for same. It becomes very time consuming if a table is having bulk records.

Here is an another way to find the rows count in table very quickly no matter how many millions rows that table is having:

SELECT object_name(object_id) As TableName ,row_count
FROM sys.dm_db_partition_stats
WHERE object_id = OBJECT_ID('Token_Output');

Note: 'Token_Output' - Table Name

In SQL Server 2008 we have the following option

exec sp_rowcount 'table name'

No comments:

Post a Comment