Users Pricing

blog

Home Blogs Count table size in SQL Server – MindStick

Count table size in SQL Server

AVADHESH PATEL 4408 14 Feb 2013 Updated 18 Sep 2014

This blog have to described, how to retrieve table size.

 Below line of code return all table’s size which associated with current database. Steps are given below

Use database

Syntax

USE <Database Name>
e.g.
USE MASTER

Copy and paste below line of code and execute query

USE MASTER 
SELECT CASE WHEN (GROUPING(sob.name)=1) THEN 'All_Tables'
   ELSE ISNULL(sob.name, 'unknown') END AS 'Table Name',
   SUM(sys.length) AS 'Size'
FROM sysobjects sob, syscolumns sys
WHERE sob.xtype='u' AND sys.id=sob.id
GROUP BY sob.name
WITH CUBE


Avadhesh Kumar Patel District Project Manager - Aligarh 14 months work experience in Panchayati Raj Department Sector as District Project Manager & 12 months work experience in IT Sector as Software Engineer. :-)


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md