Sqlserver查询出所有表的大小使用情况
发表于:2025-02-09 作者:千家信息网编辑
千家信息网最后更新 2025年02月09日,第一种方法:先查询出源表数据:select 'insert into @tmp exec sp_spaceused '+name From sys.tables with(nolock) order
千家信息网最后更新 2025年02月09日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安全错误
数据库的锁怎样保障安全
已有数据库如何添加日志文件
北京唯心互联软件开发有限公司
网络技术集团的部门
网络安全联合防控
斐讯城市服务器
vue 手机上内置web服务器
云南阿里云服务器申请虚拟主机
sql数据库视图6
和平精英竞赛题服务器没有响应
安徽私有服务器价格
更换了新的服务器
如何保证服务器内部通讯安全
数据库导入中文表乱码
网络技术员暑期实践论文
网络安全手抄报图片壁纸动漫
网网络安全小知识
软件开发过程中模型的作用
网络技术英文test
网络连接异常服务器失效
moxa串口服务器p1亮黄灯
u8数据库不存在
网络技术在会展
c软件开发平台
广州软件开发解决方案咨询
建立客户数据库的步骤
联想ST58服务器显卡驱动
数据库还原误删除的数据库
附件数据库失败
流媒体服务器端
幻塔星岛25服务器什么时候开的