Hin und wieder hätte man mal gerne eine Liste aller Tabellen um deren Größe zu kontrollieren/sehen zu können. MS-SQL hat dafür keine Boardmittel. Mit der folgenden Stored procedure kann man sich so eine Liste auf Datenbank ebene ausgeben lassen.
Mit dem Befehl Exec dbo.GetTableSpace kann man die Stored procedure ausführen.
CREATE PROCEDURE [dbo].[GetTableSpace] as SET NOCOUNT ON CREATE TABLE #TableSpace ( Rows int, DataSpaceUsed int, IndexSpaceUsed int ) DECLARE @TableSpace table ( TableName varchar(255), Rows int, DataSpaceUsed int, IndexSpaceUsed int ) DECLARE @Rows int, @DataSpaceUsed int, @IndexSpaceUsed int DECLARE @TableName varchar(255) DECLARE Table_Cursor CURSOR FOR SELECT user_name(o.uid) + '.' + o.name AS table_name FROM dbo.sysobjects o, dbo.sysindexes i WHERE OBJECTPROPERTY(o.id, N'IsTable') = 1 AND i.id = o.id AND i.indid < 2 AND o.name NOT LIKE N'#%' AND xtype = 'U' ORDER BY 1 OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @TableName INSERT INTO #TableSpace (Rows, DataSpaceUsed, IndexSpaceUsed) EXEC sp_MStablespace @TableName SELECT @Rows = Rows, @DataSpaceUsed = DataSpaceUsed, @IndexSpaceUsed = IndexSpaceUsed FROM #TableSpace INSERT INTO @TableSpace (TableName, Rows, DataSpaceUsed, IndexSpaceUsed) VALUES (@TableName, @Rows, @DataSpaceUsed, @IndexSpaceUsed) DELETE FROM #TableSpace -------------------------------- WHILE @@FETCH_STATUS = 0 BEGIN --------------------------------- --Set Data FETCH NEXT FROM Table_Cursor INTO @TableName INSERT INTO #TableSpace (Rows, DataSpaceUsed, IndexSpaceUsed) EXEC sp_MStablespace @TableName SELECT @Rows = Rows, @DataSpaceUsed = DataSpaceUsed, @IndexSpaceUsed = IndexSpaceUsed FROM #TableSpace INSERT INTO @TableSpace (TableName, Rows, DataSpaceUsed, IndexSpaceUsed) VALUES (@TableName, @Rows, @DataSpaceUsed, @IndexSpaceUsed) DELETE FROM #TableSpace -------------------------------- END CLOSE Table_Cursor DEALLOCATE Table_Cursor DROP TABLE #TableSpace SELECT * FROM @TableSpace ORDER BY Rows DESC GO