Herkese merhaba,
Bu kısımda SQL Server’da tüm tabloların boyut bilgisini alma kodları olacak.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
use NORTHWND --Database adını burdan değiştireceksiniz. set nocount on go declare @TableName varchar(128), @RID int, @MaxRID int declare @loopSrc table ( RID int identity(1,1) primary key clustered, TableName varchar(128) ) if object_id('tempdb.dbo.#Tabs') is not null drop table #Tabs create table #Tabs ( TableName varchar(128), nRows int, nReserved as cast(replace(sReserved, ' KB', '') as int), nData as cast(replace(sData, ' KB', '') as int), nIndexSize as cast(replace(sIndexSize, ' KB', '') as int), nUnused as cast(replace(sUnused, ' KB', '') as int), sReserved varchar(30), sData varchar(30), sIndexSize varchar(30), sUnused varchar(30) ) /***************************** *** INSERT LOOP ITEMS HERE *** *****************************/ insert into @loopSrc ( TableName ) select name from sys.tables select @RID = 1, @MaxRID = @@rowcount /********************** *** LOOP STRUCTURE *** **********************/ while @RID <= @MaxRID begin select @TableName = TableName from @loopSrc where RID = @RID begin try insert into #Tabs exec sp_spaceused @tableName end try begin catch end catch select @RID += 1 end select * from #Tabs order by nRows desc |
