Created
July 5, 2011 07:58
-
-
Save veggerby/1064437 to your computer and use it in GitHub Desktop.
SQL Script to Get Row Count of All Tables in Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Method 1: | |
sp_msforeachtable "SELECT '?', COUNT(*) FROM ?" | |
-- Method 2: (nicer, more details) | |
CREATE TABLE #TempTable | |
( | |
tableName varchar(100), | |
numberofRows varchar(100), | |
reservedSize varchar(50), | |
dataSize varchar(50), | |
indexSize varchar(50), | |
unusedSize varchar(50) | |
) | |
GO | |
EXEC sp_msforeachtable "INSERT #TempTable EXEC sp_spaceused '?'" | |
GO | |
SELECT * FROM #TempTable | |
DROP TABLE #TempTable | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment