Last active
December 28, 2015 03:49
-
-
Save jondlm/7438040 to your computer and use it in GitHub Desktop.
Some general scripts for SQL Server to get a data about tables in your databases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE DatabaseName | |
GO | |
CREATE TABLE #temp_table ( | |
table_name sysname , | |
row_count INT, | |
reserved_size VARCHAR(50), | |
data_size VARCHAR(50), | |
index_size VARCHAR(50), | |
unused_size VARCHAR(50)) | |
SET NOCOUNT ON | |
INSERT #temp_table | |
EXEC sp_msforeachtable 'sp_spaceused ''?''' | |
SELECT a.table_name, | |
a.row_count, | |
COUNT(*) AS col_count, | |
a.data_size | |
FROM #temp_table a | |
INNER JOIN information_schema.columns b | |
ON a.table_name collate database_default = b.table_name collate database_default | |
GROUP BY a.table_name, | |
a.row_count, | |
a.data_size | |
ORDER BY CAST(REPLACE(a.data_size, ' KB', '') AS integer) DESC | |
DROP TABLE #temp_table |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT '[' + SCHEMA_NAME(t.schema_id) + '].[' + t.name + ']' AS fulltable_name, | |
SCHEMA_NAME(t.schema_id) AS schema_name, | |
t.name AS table_name, | |
i.rows | |
FROM sys.tables t | |
INNER JOIN sys.sysindexes i | |
ON t.object_id = i.id | |
AND i.indid < 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment