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 ...
随机推荐
- 【实例图文详解】OAuth 2.0 for Web Server Applications
原文链接:http://blog.csdn.net/hjun01/article/details/42032841 OAuth 2.0 for Web Server Applicatio ...
- EntityFramework:再谈 “如何映射聚合?”
背景 在之前的文章中<DDD:使用EntityFramework的话,如果只为聚合根设计仓储,其它实体如何处理?>,我介绍了如何映射聚合以保证其语义,当时的结论是:聚合内除了聚合根之外的实 ...
- matlab中m文件与m函数的学习与理解
1. m文件与m函数的区别 所谓 MATLAB 程序,大致分为两类: M 脚本文件 (M-Script) 和 M 函数 (M-function), 它们均是普通的 ASCII 码构成的文件. M 脚本 ...
- Mysql5.7.9密码已过有效期的处理过程
怎么知道系统默认的有效期是多久呢?使用一个普通用登陆[未过期]:默认系统的密码生命周期是360天就是一年这样了: test01@(none) 09:11:43>show variables li ...
- Python 日期和时间 —— datetime
Python 日期和时间 —— datetime Python提供了多个内置模块用于操作日期时间,如calendar,time,datetime.calendar用于处理日历相关 :time提供的接口 ...
- Android -- 再来一发Intent
之前写过一篇Intent的博客,主要说了一下隐式意图. 传送门:<Android -- Intent> Intent对象构成 Component name.Action.Data.Cate ...
- 理解 select poll epoll
举例说明:老师收学生作业,相当于应用层调用I/O操作. 1.老师逐个收学生作业,学生没有做完,只能阻塞等待,收了之后,再去收下一个学生的作业.这显然存在性能问题. 2.怎么解决上面的问题? 老师找个班 ...
- Maven项目结合POI实现导入导入导入导入导入Excl表格Demo-亲测可用
第一步:写入maven依赖(3.6是比较稳定的版本,可用于生产环境) <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --& ...
- IIS 之 功能详解
IIS (Internet Information Services)信息服务管理器,本文以Windows10环境下的IIS为例,主要包含:FTP 服务器.Web 管理工具.万维网服务三大部分,如下表 ...
- java使用链栈实现数制转换
java实现链栈在前面有所介绍:http://www.cnblogs.com/lixiaolun/p/4644141.html 将前面java实现链栈的代码稍作修改: package linkedst ...