Code Snippet posted by:
Niladri.Biswas | Posted on: 4/27/2012 | Category:
SQL Server Codes | Views: 799 | Status:
[Member] |
Points: 40
|
Alert Moderator
Hi,
The below code will help us for getting the count of rows of all tables in a particular Database. Thought it may be helpful for others
-- Create a temp table for storing the information
CREATE TABLE #temp
(
[Table Name] VARCHAR(100),
[Number Of Rows] INT
)
--Execute the query and insert into the temp table
EXEC sp_msForEachTable 'INSERT INTO #temp SELECT ''?'' AS TableName,COUNT(*) AS NoOfRows FROM ?'
-- Project the result
SELECT * FROM #temp ORDER BY [Number Of Rows] DESC
-- Drop the temp table once the operation is over
DROP TABLE #temp
Best Regards,
Niladri Biswas