sql查看所有表大小的方法
发布时间:2024-01-24 04:42:13
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


猜你喜欢
- 1.图像处理库import cv2 as cvfrom PIL import *常用的图像处理技术有图像读取,写入,绘图,图像色彩空间转换,
- 下面我们用HTML来上传3个文件看看,它包含了文本描述字段和多项选择:upload.htm<HTML> <BOD
- Python 字符串字符串是 Python 中最常用的数据类型。我们可以使用引号来创建字符串。创建字符串很简单,只要为变量分配一个值即可。例
- 如下所示:file->settings->Editor->General->Console里面的console co
- 因为云服务器的centos是没有图形界面的,所以安装比较麻烦,刚好19c有本地rpm的安装方法,所以推荐用rpm安装。首先到官网下载rpm包
- 目前有好几种方法可以将python文件打包成exe应用程序文件,例如py2exe,pyinstaller等,比较下来,还是觉得pyinsta
- 如何用SQLMail建立一个电子刊物自动处理系统?下面我们用SQLMail来做一个电子刊物自动处理系统。在这个系统中,主要实现两个功能:1、
- 1. 传值与传址的区别传值就是传入一个参数的值,传址就是传入一个参数的地址,也就是内存的地址(相当于指针)。他们的区别是如果函数里面对传入的
- 闭包(closure)不是什么可怕的东西。如果用对了地方,它们其实可以很强大。闭包就是由其他函数动态生成并返回的函数,通俗地讲,在一个函数的
- 今天我给大家分享的是在不刷新页面的前提下,使用PHP+jQuery+Ajax实现多图片上传的效果。用户只需要点击选择要上传的图片,然后图片自
- 大家好,使用 Python Flask 创建 URL 缩短器是一个有趣而简单的项目,可以帮助您深入了解 Web 开发的世界。Flask 是
- 一、竞态条件与临界区和同步工具(1)竞态条件一旦数据被多个线程共享,那么就会产生冲突和争用的情况,这种情况被称为竞态条件。这往往会破坏数据的
- 开发高质量软件的过程中,我们经常会为每个函数编写测试,这样在开发过程中运行这些测试的时候就比较方便,doctest是一个python标准库自
- 从cnblogs看到的代码,作者的代码随便不兼容firefox但,有助于大家学习为什么下面的代码兼容了firefox,大家可以对比下,有助于
- 向量点乘 (dot) 和对应分量相乘 (multiply) :>>> aarray([1, 2, 3])>>&
- TEMPLATESDjango 1.8的新特性一个列表,包含所有在Django中使用的模板引擎的设置。列表中的每一项都是一个字典,包含某个引
- 绘制直线图,确定x范围和y的范围代码:import matplotlib.pyplot as pltimport numpy as npxp
- 当前的调试部分可以使用 go run filename.go 来执行。可以生成一个 build.sh 脚本,用于在指定位置产生已编译好的 可
- 参考文档 https://cli.vuejs.org/zh/1.安装npm install -g @vue/cli2.检查安装vue -V
- 本文实例为大家分享了python实现记事本功能的具体代码,供大家参考,具体内容如下1. 案例介绍tkinter 是 Python下面向 tk