sqlserver 用於檢視當前資料庫所有表占用空間大小的儲存過程
createprocedure
dbo.proc_getsize
asbegin
create
table #temp
( t_id
intprimary
keyidentity(1,1
), t_name sysname,
--表名
t_rows int, --
總行數 t_reserved varchar(50), --
保留的空間總量
t_data varchar(50), --
資料總量
t_indexsize varchar(50), --
索引總量
t_unused varchar(50) --
未使用的空間總量
)exec sp_msforeachtable n'
insert into #temp(t_name,t_rows,t_reserved,t_data,t_indexsize,t_unused) exec sp_spaceused ''?
'''select
t_id,t_name,t_rows,t_reserved,t_indexsize,t_unused,t_data,
case
when
cast(replace(t_data,'
kb','') as
float)>
1000000
then
cast(cast(replace(t_data,'
kb','') as
float)/
1000000
asvarchar)+'gb
'when
cast(replace(t_data,'
kb','') as
float)>
1000
then
cast(cast(replace(t_data,'
kb','') as
float)/
1000
asvarchar)+'mb
'else t_data end
asdatasize
from #temp
order
bycast(replace(t_data,'
kb','') as
float) desc
drop
table #temp
end
sqlserver檢視表占用空間大小
定義表變數 定義表變數 declare ttable name varchar max rows int reserved varchar max data size varchar max index size varchar max unused size varchar max 將表占用情況存...
檢視表空間
檢視某錶的大小 select sum bytes 1024 1024 as size m from user segments where segment name upper tbl mo part 00 檢視索引個數和類別 select index name,index type,table n...
檢視表占用空間資訊
if not exists select from dbo.sysobjects where id object id n dbo tablespaceinfo and objectproperty id,n isusertable 1 create table tablespaceinfo 建立臨...