devxlogo

Get the Total Number of Rows for Each Table in Your Database

Get the Total Number of Rows for Each Table in Your Database

Use the following query to get the total number of rows for each table in your database:

CREATE TABLE #TempTable  (  [Table Name] [varchar](max),    [Total Records] int  );    EXEC sp_MSForEachTable @command1 = ' Insert Into #Tab(Table_Name, Total_Records) SELECT ''?'', COUNT(*) FROM ?'    SELECT * FROM #TempTable t ORDER BY t.[Total Records] DESC;    DROP TABLE #TempTable;
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist