sql查看所有表大小的方法
sql查看所有表大小的方法。
代码:
declare @id int
declare @type character(2)
declare @pages int
declare @dbname sysname
declare @dbsize dec(15,0)
declare @bytesperpage dec(15,0)
declare @pagesperMB dec(15,0)
create table #spt_space
(
[objid] int null,
[rows] int null,
[reserved] dec(15) null,
[data] dec(15) null,
[indexp] dec(15) null,
[unused] dec(15) null
)
set nocount on
-- Create a cursor to loop through the user tables
declare c_tables cursor for
select id from sysobjects where xtype = 'U'
open c_tables fetch next from c_tables into @id
while @@fetch_status = 0
begin --- www.jbxue.com
/* Code from sp_spaceused */
insert into #spt_space (objid, reserved)
select objid = @id, sum(reserved)
from sysindexes
where indid in (0, 1, 255) and id = @id select @pages = sum(dpages)
from sysindexes
where indid < 2
and id = @id select @pages = @pages + isnull(sum(used), 0)
from sysindexes
where indid = 255 and id = @id update #spt_space set data = @pages
where objid = @id /* index: sum(used) where indid in (0, 1, 255) - data */ update #spt_space
set indexp = (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id) - data
where objid = @id /* unused: sum(reserved) - sum(used) where indid in (0, 1, 255) */
update #spt_space
set unused = reserved - (
select sum(used)
from sysindexes
where indid in (0, 1, 255) and id = @id
)
where objid = @id update #spt_space set [rows] = i.[rows]
from sysindexes i
where i.indid < 2 and i.id = @id and objid = @id fetch next from c_tables into @id
end
select TableName = (select left(name,60) from sysobjects where id = objid),
[Rows] = convert(char(11), rows),
ReservedKB = ltrim(str(reserved * d.low / 1024.,15,0) + ' ' + 'KB'),
DataKB = ltrim(str(data * d.low / 1024.,15,0) + ' ' + 'KB'),
IndexSizeKB = ltrim(str(indexp * d.low / 1024.,15,0) + ' ' + 'KB'),
UnusedKB = ltrim(str(unused * d.low / 1024.,15,0) + ' ' + 'KB')
from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = 'E'
order by reserved desc
drop table #spt_space
close c_tables
deallocate c_tables
sql查看所有表大小的方法的更多相关文章
- SQL 查看数据库表的容量大小
--==============查看数据库表的容量大小========start================================?============ Create Table # ...
- SQL查看所有表的大小
--查看所有表的大小 declare @id int ) declare @pages int declare @dbname sysname ,) ,) ,) create table #spt_s ...
- mysql工具——使用mysqlshow查看mysql对象信息,查看mysql表大小
关键词:查看表大小,mysqlshow mysqlshow --count -uroot -p test
- PostgreSQL 查看单表大小
1. 在数据库中查单个表 select pg_size_pretty(pg_relation_size('table_name')); 2. 查出并按大小排序 SELECT table_schema ...
- SQL Server查看所有表大小、表行数和占用空间信息
一.查看表名和对应的数据行数select a.name as '表名',b.rows as '表数据行数'from sysobjects a inner join sysindexes bon a. ...
- SQL Server查看所有表大小,所占空间
create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),index_ ...
- postgresql 查看单个表大小
3中方法,不论什么一个都行 方法一 ,查一个表 select pg_size_pretty(pg_relation_size('table_name')); 方法二 ,查出全部表并按大小排序 SELE ...
- sql server数据表大小初始化
sql server表在存储大数据和处理大数据表时,经常会遇到表空间越来越大,有时候会超出应该占有空间大小很多,此时如果表数据是压缩存储的,那么重新执行一下压缩脚本,数据的大小会重新初始化,然后再使用 ...
- SQL server2000 创建表单的方法(已实践检验)
我的系统是win7旗舰版的,在安装完SQL server2000之后,单击表,右键-新建表时,系统要么弹出:MMC检测到此管理单元发生一个错误.要么直接弹出microsoft sql server 2 ...
随机推荐
- Windows 配置 Apache Python CGI
提示:安装Apache可参考 https://jingyan.baidu.com/article/0eb457e53c019f03f1a905c7.html 1. 打开URL: https://ww ...
- OAuth:第一天学习OAuth
收集的一些资料 http://baike.baidu.com/view/3948029.htm. http://oauth.net/. 使用百度的OAuth服务进行测试 代码下载:http://yun ...
- Git分支模型
转自:http://www.cnblogs.com/byeyear/archive/2012/11/28/2793374.html 本文介绍一种使用Git进行源代码管理的分支模型,着重于如何使用Git ...
- eclipse下使用git上传(下载)代码至(从)github
eclipse下使用git插件上传代码至github 1.eclipse下安装git 正常情况下,eclipse 是自带 git 插件的,那么即可跳至步骤1的最后一小步,配置 git . 如果十分悲剧 ...
- LaTeX绘图宏包 Pgfplots package
Pgfplots package The pgfplots package is a powerful tool, based on tikz, dedicated to create scienti ...
- Delphi 6 保存窗体设置
DSK Desktop Setting File 保存工程文件的桌面摆布情况, 下次打开时可以恢复上次保存的桌面状态 Desktop文件.保存了IDE的布局(也可能包含浏览记号,视乎IDE的设定),为 ...
- 未能加载文件或程序集“Antlr3.Runtime”或它的一个依赖项的解决办法
一.问题症状 未能加载文件或程序集“Antlr3.Runtime”或它的一个依赖项.参数错误. 二.问题起因和经过 今天我在虚拟机下做开发,asp.net mvc4开发测试微信接口,一不小心虚拟机 ...
- js 多域名跳转
<script>try {if( self.location == "http://cnblogs.com/endv" ) { top.location.href = ...
- Python写的简陋版一对一聊天工具,全双工
好该睡觉了,明天还要上班~~~直接上代码,后面再总结 import threading import os import socket def RecvProcess ( UDP_Socket, Lo ...
- Android调用系统拍照裁剪和选图功能
最近项目中用到修改用户头像的功能,基本上都是模板代码,现在简单记录一下. 调用系统拍照 private fun openCamera() { //调用相机拍照 // 创建File对象,用于存储拍照后的 ...