Skip to content

Instantly share code, notes, and snippets.

@veggerby
Created July 5, 2011 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veggerby/1064437 to your computer and use it in GitHub Desktop.
Save veggerby/1064437 to your computer and use it in GitHub Desktop.
SQL Script to Get Row Count of All Tables in Database
-- 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