Sqlserver查询出所有表的大小使用情况
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,第一种方法:先查询出源表数据:select 'insert into @tmp exec sp_spaceused '+name From sys.tables with(nolock) order
千家信息网最后更新 2025年11月07日Sqlserver查询出所有表的大小使用情况第一种方法:
先查询出源表数据:
select 'insert into @tmp exec sp_spaceused '+name From sys.tables with(nolock) order by create_date desc;
创建临时表并把查询出来的源表数据insert进入临时表,再查询出来最后临时表里面的数据:
declare @tmp table(tbname varchar(255),tbrows int,reserved varchar(255),datatb varchar(255),index_size varchar(255),unused varchar(255))
insert into @tmp exec sp_spaceused table1
insert into @tmp exec sp_spaceused table2
insert into @tmp exec sp_spaceused table3
insert into @tmp exec sp_spaceused table4
insert into @tmp exec sp_spaceused table5
insert into @tmp exec sp_spaceused table6
insert into @tmp exec sp_spaceused table7
insert into @tmp exec sp_spaceused table8
insert into @tmp exec sp_spaceused table9
insert into @tmp exec sp_spaceused table10
select * from @tmp order by cast(replace(reserved,' KB','') as bigint) desc
得出最后想要的数据结果。
第二种方法:
select
tb.name as tbname
,ps.reserved_page_count * 8 as KB
,ps.row_count
From
sys.dm_db_partition_stats ps with(nolock)
,sys.tables tb with(nolock)
where
ps.object_id=tb.object_id
and tb.create_date >= '2017-10-23 21:44:15.010'
order by
ps.reserved_page_count desc
先查询出源表数据:
select 'insert into @tmp exec sp_spaceused '+name From sys.tables with(nolock) order by create_date desc;
创建临时表并把查询出来的源表数据insert进入临时表,再查询出来最后临时表里面的数据:
declare @tmp table(tbname varchar(255),tbrows int,reserved varchar(255),datatb varchar(255),index_size varchar(255),unused varchar(255))
insert into @tmp exec sp_spaceused table1
insert into @tmp exec sp_spaceused table2
insert into @tmp exec sp_spaceused table3
insert into @tmp exec sp_spaceused table4
insert into @tmp exec sp_spaceused table5
insert into @tmp exec sp_spaceused table6
insert into @tmp exec sp_spaceused table7
insert into @tmp exec sp_spaceused table8
insert into @tmp exec sp_spaceused table9
insert into @tmp exec sp_spaceused table10
select * from @tmp order by cast(replace(reserved,' KB','') as bigint) desc
得出最后想要的数据结果。
第二种方法:
select
tb.name as tbname
,ps.reserved_page_count * 8 as KB
,ps.row_count
From
sys.dm_db_partition_stats ps with(nolock)
,sys.tables tb with(nolock)
where
ps.object_id=tb.object_id
and tb.create_date >= '2017-10-23 21:44:15.010'
order by
ps.reserved_page_count desc
数据
查询
方法
结果
表里
面的
大小
情况
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
一千元一个阿里云服务器
软件开发公司专利
华为 oxc软件开发
list数据库
体育局网络安全自查情况汇报
excelvba外部数据库
德州润昌软件开发
阿里巴巴网络安全牛人吴翰清
linux 安装数据库
文明重启工程服务器怎么设置
大华存储服务器一直报警
医学数据库等级
大数据库技术原理
网络安全法约束力描述
科技和工业互联网
云南数字化城管软件开发
怎么填充上一行的数据库
服务器主机可以带显示屏吗
软件开发斗牛
多措并举助力网络安全
加强网络安全方案
vb显示采集数据库
abs函数数据库
编程软件开发需要学习什么
职校中的智能化网络技术
兴业银行软件开发中心
未成年人违法数据库
跨表格操作数据库
只会c语言可以投软件开发吗
康海串口服务器