查看Sql表所占空间的大小

create table #tablespaceinfo 

(nameinfo varchar(50) ,

rowsinfo int ,

 reserved varchar(20) ,

datainfo

varchar ( 20 ) ,

index_size

varchar ( 20 ) ,

unused

varchar ( 20 ) )

declare

@tablename varchar ( 255 )

declare

@cmdsql varchar ( 500 )

DECLARE

Info_cursor CURSOR

FOR select o.name from dbo.sysobjects o where OBJECTPROPERTY(o.id, N'IsTable') = 1  

and o.name not like N'#%%' order by o.name

OPEN

FETCH NEXT FROM Info_cursor INTO @tablename WHILE @@FETCH_STATUS = 0

Info_cursor

 

BEGIN

set @tablename = 'SchemaName.'+@tablename 

if exists (select * from dbo.sysobjects where id = object_id(@tablename) and OBJECTPROPERTY(id, N'IsUserTable') = 1)

 

execute

sp_executesql

N'insert into #tablespaceinfo exec sp_spaceused @tbname',

N'@tbname varchar(255)',

@tbname

 

= @tablename

FETCH NEXT FROM Info_cursor INTO @tablename 

 

 

END

CLOSE

 

Info_cursor

DEALLOCATE

 

Info_cursor

GO

 

 

sp_spaceused 

@updateusage = 'TRUE'

select 

 

* from#tablespaceinfo

order by cast(left(ltrim(rtrim(reserved)) , len(ltrim(rtrim(reserved)))-2) as int) desc

 

 

使用时注意替换SchemaName,若为 Sql2000,则将

set @tablename = 'SchemaName.'+@tablename+@tablename+@tablename 删除。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值