DEFINITIONS

Definitions More Info.
Definition ID145
TitleSQL
CategoryMS_SCRIPT
DefinitionDetailedListOfAllTablesAndSize
Definition Description-- List all database tables and there indexes with
-- detailed information about row count and
-- used + reserved data space.

-- MODIFIYE SORGU
USE MailDB;
GO
SELECT
t.Name AS TableName,
s.Name AS SchemaName,
p.Rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
((SUM(a.total_pages) * 8)/1024) AS TotalSpaceMB,
((SUM(a.total_pages) * 8)/1024)/1024 AS TotalSpaceGB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
p.data_compression_desc
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
p.data_compression=0
AND t.is_ms_shipped = 0
AND i.object_id > 255
GROUP BY
t.Name, s.Name, p.Rows,p.data_compression,p.data_compression_desc
ORDER BY
TotalSpaceGB;
GO


--- ORJINAL SORGU

USE AtlantisDB;
GO
SELECT
t.Name AS TableName,
s.Name AS SchemaName,
p.Rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
((SUM(a.total_pages) * 8)/1024)/1024 AS TotalSpaceGB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
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
TotalSpaceGB;
GO
RecordBycunay
Record Date21-02-2012 12:19:03
Düzenle
Kopyala
Sil