What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 18071 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > SQL Server > Obtain Row count of all the tables in Sql Server ...
Niladri.Biswas

Obtain Row count of all the tables in Sql Server

 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
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 12:39:38 AM