Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql server list table sizes

SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
    CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    TotalSpaceMB DESC, t.Name
Comment

PREVIOUS NEXT
Code Example
Sql :: sql last row in table 
Sql :: Failed to stop mysql.service: Unit mysql.service not loaded. 
Sql :: oracle all_source package body 
Sql :: mysql interval 1 day 
Sql :: find table for column name in sql 
Sql :: VERIFY INDEXES IN SQL ORACLE 
Sql :: show all sequence in postgresql 
Sql :: truncate table mysql 
Sql :: sql drop view if exists 
Sql :: oracle start job 
Sql :: create table sql server 
Sql :: restart mysql server ubuntu 
Sql :: [2021-10-05T13:43:48.961Z] error Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client 
Sql :: grant lock tables privilege mysql 
Sql :: postgres delete database 
Sql :: how to get all table names in sql query 
Sql :: install mysql workbench ubuntu 20.04 terminal 
Sql :: how to give user privelege to create dblink in oracle 
Sql :: drop db syntax 
Sql :: describe table mysql 
Sql :: select item.* as json mysql 
Sql :: sql sum if 
Sql :: postgres update column with value from another table 
Sql :: postgresql random number 
Sql :: get the mysql table columns data type mysql 
Sql :: create table sql server auto increment primary key 
Sql :: postgresql make each element in array distinct 
Sql :: oracle split string 
Sql :: create table with primary key auto increment in sql 
Sql :: select sql in descending order 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =