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查看所有表大小的方法的更多相关文章

  1. SQL 查看数据库表的容量大小

    --==============查看数据库表的容量大小========start================================?============ Create Table # ...

  2. SQL查看所有表的大小

    --查看所有表的大小 declare @id int ) declare @pages int declare @dbname sysname ,) ,) ,) create table #spt_s ...

  3. mysql工具——使用mysqlshow查看mysql对象信息,查看mysql表大小

    关键词:查看表大小,mysqlshow mysqlshow --count -uroot -p test

  4. PostgreSQL 查看单表大小

    1. 在数据库中查单个表 select pg_size_pretty(pg_relation_size('table_name')); 2. 查出并按大小排序 SELECT table_schema ...

  5. SQL Server查看所有表大小、表行数和占用空间信息

    一.查看表名和对应的数据行数select  a.name as '表名',b.rows as '表数据行数'from sysobjects a inner join sysindexes bon a. ...

  6. SQL Server查看所有表大小,所占空间

    create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),index_ ...

  7. postgresql 查看单个表大小

    3中方法,不论什么一个都行 方法一 ,查一个表 select pg_size_pretty(pg_relation_size('table_name')); 方法二 ,查出全部表并按大小排序 SELE ...

  8. sql server数据表大小初始化

    sql server表在存储大数据和处理大数据表时,经常会遇到表空间越来越大,有时候会超出应该占有空间大小很多,此时如果表数据是压缩存储的,那么重新执行一下压缩脚本,数据的大小会重新初始化,然后再使用 ...

  9. SQL server2000 创建表单的方法(已实践检验)

    我的系统是win7旗舰版的,在安装完SQL server2000之后,单击表,右键-新建表时,系统要么弹出:MMC检测到此管理单元发生一个错误.要么直接弹出microsoft sql server 2 ...

随机推荐

  1. Oracle数据库常用函数使用--持续更新中

    NVL函数.NVL( string1, replace_with).如果string1为NULL,则NVL函数返回replace_with的值,否则返回原来的值. INSTR函数.用于查找指定字符串是 ...

  2. Mac通过wifi连接 Android设备

    公司用的全是mac开发,但是全是type-C接口,每次背电脑回家啊,还得带个数据线转换器…… 想着回来,直接通过Wi-Fi连接手机就好,发现完全忘了之前套路,现在赶紧记下一波,保证包教包会! STEP ...

  3. VB--"." 和 "!" ?

    在做学生信息管理系统的时候,遇到了一条代码. txtName.Text = mrc!student_Name txtResult.Text = mrc!result 代码本身理解没有问题,给文本框添加 ...

  4. /etc/skel 目录作用

    /etc/skel包含的文件和目录会被自动复制到一个新用户的家目录(当使用 useradd 程序创建用户时)./etc/skel允许系统管理员给所有的新用户创建一个默认的家目录,这样所有的新用户都有一 ...

  5. [转] 菜鸟手脱VMP,附上脱壳过程和自己写的脚本,可跨平台

    转载:http://www.52pojie.cn/thread-467703-1-1.html 工作需要要脱一个VMP壳,我是一个从来没接触过脱壳的人.瞬间那种心情遇到的人应该都知道!没办法硬着头皮找 ...

  6. css3新单位vw、vh、vmin、vmax的使用介绍

    1,vw.vh.vmin.vmax 的含义 (1)vw.vh.vmin.vmax 是一种视窗单位,也是相对单位.它相对的不是父节点或者页面的根节点.而是由视窗(Viewport)大小来决定的,单位 1 ...

  7. MyEclipse 全面的快捷键

    摘自: http://www.360doc.com/content/11/0406/10/6704374_107513559.shtml 引用 MyEclipse快捷键(全面) 程序代码自动排版:Ct ...

  8. Linux laravel安装

    第一步:安装php套件 目前为止laravel是5.1版本,需要对php有要求,要php5.59以上 The Laravel framework has a few system requiremen ...

  9. HTML5-IOS WEB APP应用程序(IOS META)

    触摸屏网站的开发其实现在来讲比前几年移动端网站开发好多了,触摸屏设备IOS.Android.BBOS6等系统自带浏览器均为WEBKIT核心,这就说明PC上面尚未立行的HTML5 CSS3能够运用在这里 ...

  10. 智能化的命令行工具-betty

    本文首先公布在 CSDN的文章编辑器实在太烂了,建议大家用Cmd Markdown.它不但支持markdown.还支持VIM模式. 智能化的命令行工具-betty betty tool command ...