Auflistung aller definierten Objekte in MS-SQL Datenbank
Ein SQL-Skript um alle gespeicherten Stored Procedures, Functions und Views in einer MS-SQL Datenbank aufzulisten:
/**
Auflistung der Procedures, Funktionen und Views
**/
SELECT
sm.object_id AS 'ID'
,OBJECT_NAME(sm.object_id) AS 'Name'
,o.type AS 'Typ'
,o.type_desc AS 'Bezeichnung'
,o.modify_date AS 'Datum'
,sm.definition AS 'SQL'
FROM sys.sql_modules AS sm
JOIN sys.objects AS o ON sm.object_id = o.object_id
ORDER BY o.type, Name;
Alle Objekte k�nnen auch �ber sys.objects aufgelistet werden, Tabellen �ber sys.tables. Alle Tabellen mit Gr��en:
/**
Auflistung aller Tabellen mit Namen, Schema und Gr��e
**/
SELECT
t.name AS 'Name'
,s.name AS 'SchemaName'
,p.rows AS 'Zeilen'
,SUM(a.total_pages) * 8 AS 'KB'
,FORMAT(CAST(SUM(a.total_pages) * 8 AS FLOAT) / 1024, 'N', 'de-de') AS 'MB'
,FORMAT(CAST(SUM(a.total_pages) * 8 AS FLOAT) / (1024*1024), 'N', 'de-de') AS 'GB'
FROM sys.tables t
LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id
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
GROUP BY
s.name, t.Name, p.rows
ORDER BY t.name