Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sql-queries-12/database-size/mssql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
EXEC sp_spaceused;

SELECT DB_NAME(database_id) AS [Database], CAST(SUM(size) * 8 / 1024 AS VARCHAR(20)) + ' MB' AS [Size]
FROM sys.master_files
WHERE DB_NAME(database_id) = 'university'
GROUP BY database_id;

SELECT d.name AS [Database], CAST(SUM(mf.size) * 8 / 1024 AS VARCHAR(20)) + ' MB' AS [Size]
FROM sys.databases d
JOIN sys.master_files mf
ON d.database_id = mf.database_id
GROUP BY d.name
ORDER BY SUM(mf.size) DESC;
9 changes: 9 additions & 0 deletions sql-queries-12/database-size/mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT table_schema AS "Database", FLOOR(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.tables
WHERE table_schema = 'university'
GROUP BY table_schema;

SELECT table_schema AS "Database", FLOOR(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.tables
GROUP BY table_schema
ORDER BY SUM(data_length + index_length) DESC;
7 changes: 7 additions & 0 deletions sql-queries-12/database-size/postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT pg_database.datname AS "Database", size_pretty(pg_database_size(pg_database.datname)) AS "Size"
FROM pg_database
WHERE datname = 'university';

SELECT datname AS "Database", pg_size_pretty(pg_database_size(datname)) AS "Size"
FROM pg_database
ORDER BY pg_database_size(datname) DESC;