Count of records of all tables in current database

,

This script gives the count of records of each user table in the current database along with the table name.

/*
	Writen by 	: Vivek Agrawal	
	Description 	: This script gives the count of records of each user table in the current database along with the table name.
*/
declare @table_name varchar(280)
declare cur_temp cursor 
for 
	select name from sysobjects where OBJECTPROPERTY(id, N'IsTable') = 1 and name not like 'sys%'

open cur_temp

-- Perform the first fetch.

FETCH NEXT FROM cur_temp into @table_name

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.

WHILE @@FETCH_STATUS = 0

BEGIN

-- This is executed as long as the previous fetch succeeds.

	exec('select ''' + @table_name + ' -------- '', count(*) from ' + @table_name)

	FETCH NEXT FROM cur_temp into @table_name
END
  
CLOSE cur_temp
DEALLOCATE cur_temp

Rate

Share

Share

Rate