Submit a ticketCall us

AnnouncementsFace your biggest database issues head-on

Our new eCourse helps you navigate SQL Server performance blocks by teaching you how to recognize and deal with the three DBA Disruptors: Performance Hog, Blame Shifter, and Query Blocker. Register today to learn how to defend your environment and fend off menacing disruptions.

Register for your free eCourse.

Home > Success Center > Orion Platform > Orion - Knowledgebase Articles > Find the size of each table in the Orion database

Find the size of each table in the Orion database

Table of contents
Created by Michael Perez, last modified by MindTouch on Jun 23, 2016

Views: 2,565 Votes: 2 Revisions: 6

Overview

This article describes how you can query the Orion database to get the following:

  • Table Names
  • Row Count per table
  • Column Count per table
  • Data Size per table

There are many scenarios on which it can be handy to check how large each table is in the Orion database. 

Environment

All Orion Core products

Steps

Run the following query from Microsoft SQL Management Studio to get a count of tables by row:

 

--Start--

CREATE TABLE #temp ( table_name sysname , row_count INT, reserved_size VARCHAR(50), data_size VARCHAR(50),

index_size VARCHAR(50), unused_size VARCHAR(50))

SET NOCOUNT ON INSERT #temp

EXEC sp_msforeachtable 'sp_spaceused ''?'''

SELECT a.table_name, a.row_count, COUNT(*) AS col_count, a.data_size

FROM #temp a INNER JOIN information_schema.columns b ON a.table_name

collate database_default = b.table_name collate database_default

GROUP BY a.table_name, a.row_count, a.data_size

ORDER BY CAST(REPLACE(a.data_size, ' KB', '') AS integer) DESC

DROP TABLE #temp

--End--

 

The screen shot below is an example result.  The results will be ordered by data size from greatest to least.  

 

Last modified

Tags

Classifications

Public