Sqlserver查询出所有表的大小使用情况
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,第一种方法:先查询出源表数据:select 'insert into @tmp exec sp_spaceused '+name From sys.tables with(nolock) order
千家信息网最后更新 2026年11月01日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安全错误
数据库的锁怎样保障安全
精品咖啡豆
有格互联网科技
互联网科技工作委员会主任
互联网科技卖菜
宜安科技 互联网金融
中国互联网金融科技基金
居家互联网科技有限公司
互联网科技类展会
深圳市运趣互联网科技有限公司
中盈科技互联网信息有限公司
深圳国际航运科技和互联网
中国互联网有什么科技含量
顶级互联网科技成果有哪些
长沙茂晟互联网科技有限公司
伊宁互联网科技做什么的
中天科技中国工业互联网
厦门江牛科技互联网
抖集互联网科技技术咨询
互联网科技和医药行业
现代互联网科技公司
互联网科技咨询
互联网金融和金融科技
深圳市运趣互联网科技有限公司
互联网科技实习生岗位职责
互联网金融中的现代科技
互联网科技的全部知识
科技和互联网行业的特点
银川新华互联网科技学校招聘
六子台科技互联网展会
株洲百竞科技的互联网营销顾问