Get record count for a specific database

/ Published in: SQL
Save to your folder(s)

Copy this code and paste it in your HTML
  1. --Specify the name of the database to count in the following line
  2. USE AdventureWorks; --Added by James_DBA
  3. GO
  5. --Code modified from original posting on SQLServerCentral.Com
  6. --URL:
  7. SELECT AS "Table Name", i.rowcnt AS "Row Count"
  8. FROM sysobjects o, sysindexes i
  9. WHERE =
  10. AND indid IN(0,1)
  11. --This specifies 'user' databases only
  12. AND xtype = 'u' --Added by James_DBA
  13. --This omits the diagrams table of the database
  14. --You may find other system tables will need to be ommitted,
  15. --you would just name them all here using the <> operator
  16. --i.e. <> dtproperties, <> 'sysdiagrams'
  17. AND <> 'sysdiagrams' --Added by James-DBA
  19. --You could also look further into filtering out temp tables,
  20. --or user specified tables
  21. ORDER BY i.rowcnt DESC --I found it more useful to display
  22. --the results by 'Row Count' Descending
  23. --The original posting suggested to sort by Table name by
  24. --using the following line, instead of the line I use above:
  25. --ORDER BY
  27. --The following line adds up all the rowcount results and places
  28. --the final result into a seperate column (below the first resulting table)
  29. COMPUTE SUM(i.rowcnt); --Added by James_DBA
  30. GO


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.