Get SQL server table size
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
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
t.Name
Learn how to get SQL server table size using Skyvia Query - online SQL query builder
Run This and Other Queries Online in Skyvia Query
Skyvia Query allows you to run SQL queries against databases and cloud applications from web browser. Access and manage your data from anywhere, build reports, arrange your data in the most informative way and simplify your decision-making process easily!
Key Features
- Ability to use SQL against cloud data
- Visual query builder
- Data export
- Five free queries per day
Frequently Asked Questions
What can I use gallery queries for?
Our pre-built queries helps you quickly analyze and report on your data without building a query from scratch or perform DML operations and mass data updates.
Which data sources can I run queries on?
Skyvia Query supports cloud apps, databases, and other connected data sources available in Skyvia.
Can I get query results to a spreadsheet?
Yes. You can use Skyvia Query Google Sheets Add-on or Excel Add-in to query data directly to your workbooks. Alternatively, you can export the results of any query to CSV.
Do I need advanced SQL knowledge to use prebuilt queries?
No. Prebuilt queries can be used as ready-made examples and adjusted if needed.