找回密码
 注册账号

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

初学者课程:T3自学|T6自学|U8自学软件下载课件下载工具下载资料:通资料|U8资料|NC|培训|年结积分规则 | 使用常见问题Q&A
知识库:U8 | | NC | U9 | OA | 政务U8|U9|NCC|NC65|NC65客开|NCC客开新手必读 | 任务 | 快速增金币用友QQ群[微信群]
查看: 4653|回复: 9

[经验] 检查数据库表的空间使用情况

[复制链接]
发表于 2010-11-8 09:57:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册账号

×
本帖最后由 windy8848 于 2011-4-15 09:52 编辑
  1. --检查数据库表的使用情况
  2. exec sp_MSForEachTable
  3. @precommand=N'
  4. create table ##(
  5. id int identity,
  6. 表名 sysname,
  7. 字段数 int,
  8. 记录数 int,
  9. 保留空间 Nvarchar(10),
  10. 使用空间 varchar(10),
  11. 索引使用空间 varchar(10),
  12. 未用空间 varchar(10))',
  13. @command1=N'insert ##(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_spaceused ''?''
  14. update ## set 字段数=(select count(*) from syscolumns where id=object_id(''?'')) where id=scope_identity()',
  15. @postcommand=N'select * from ## where 记录数<>0 order by cast(replace(使用空间,''KB'','''') as int) desc ; drop table ##'



  16. --数据库库表空间大小查询
  17. select '['+rtrim(8*dpages/1024)+'Mb'+']'+object_name(id) tablename,8*reserved/1024 reserved
  18. ,rtrim(8*dpages/1024)-8*reserved/1024 r5 from sysindexes
  19. where reserved<>'0'
  20. and ( indid=0 or indid=1)
  21. group by sysindexes.dpages,sysindexes.id,sysindexes.reserved,sysindexes.dpages
  22. having (8*dpages/1024)<>0
  23. order by reserved,r5 desc
复制代码
发表于 2010-11-8 22:50:08 | 显示全部楼层
看过,好,受用
发表于 2011-3-27 08:48:28 | 显示全部楼层
谢了,试试看。
发表于 2011-4-22 08:22:38 | 显示全部楼层
谢谢分享!!
发表于 2011-4-25 16:51:11 | 显示全部楼层
好东西。谢谢分享!
发表于 2011-5-23 10:46:04 | 显示全部楼层
看看 试试  ^_^  谢谢
发表于 2011-7-12 18:44:41 | 显示全部楼层
不错............................
发表于 2012-2-3 09:59:56 | 显示全部楼层
谢谢分享。
回复 点赞 拍砖

使用道具 举报

发表于 2012-11-4 14:45:08 | 显示全部楼层
这个语句不错,挺实用的,谢谢
回复 点赞 拍砖

使用道具 举报

发表于 2013-11-23 21:26:33 | 显示全部楼层
已测试,不错,支持
回复 点赞 拍砖

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|站长微信|Archiver|手机版|小黑屋|用友之家 ( 蜀ICP备07505338号|51072502110008 )

GMT+8, 2024-4-28 05:38 , Processed in 0.040801 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表