sql语句在sql server中查询每个表的记录数,占用的空间,索引占用的空间等
来源:互联网 发布:java权限管理设计rbac 编辑:程序博客网 时间:2024/04/29 01:39
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
/* 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 server中查询每个表的记录数,占用的空间,索引占用的空间等
- sql 语句列出数据库中的表的记录数、占用空间大小等
- 查看sql server每个表占用的空间大小
- SQL Server 统计数据库中所有表的记录数和占用空间
- 查看表占用空间的sql语句
- 查看SQL Server中某数据库下每个表占用的空间大小
- Mysql数据库查询每个表占用空间的语句
- 查看SQL SERVER中指定数据库的每个表的数据量和每行记录所占用的空间
- 查询SQL Server中数据库的各个表所占用的空间
- 查询SQL Server中表占用的空间方法
- 查询SQL Server中表占用的空间方法
- SQL Server中查询CPU占用高的SQL语句
- SQL Server中查询CPU占用高的SQL语句
- SQL Server中查询CPU占用高的SQL语句
- SQL Server中查询CPU占用高的SQL语句
- SQL Server中NULL的正确使用与空间占用
- 查询数据库中所有表占用空间的语句
- 技巧:查看sql server表空间的占用方法
- Android 对话框(Dialog)大全 建立你自己的对话框
- 黑马程序员__c语言预编译指令和typedef的使用
- 国际会所占地方很占地方
- 至芯FPGA培训中心-1天FPGA设计集训(赠送FPGA开发板)
- smslib 读不了短信的异常
- sql语句在sql server中查询每个表的记录数,占用的空间,索引占用的空间等
- java:浅谈数组与对象的内存控制
- 7-2 多线程练习-——卖票程序(方法二)
- js live方法
- 编程珠玑笔记第一章
- 二叉树的遍历(递归与迭代)
- linux定时执行脚本
- 根据屏幕动态设置view的宽度 DisplayMetrics dip2px
- InStallShield 检测dotnet2.0