MSSQL查询数据库表数据大小等情况

1.查询数据库大小

SELECT 
    DB_NAME(database_id) AS '数据库名',
    [Name] AS '逻辑库名',
    [Physical_Name] AS '物理文件',
    ((size * 8) / 1024) AS '文件大小(MB)',
    [differential_base_time] AS '基准时间'
FROM sys.master_files
WHERE DB_NAME(database_id) like 'FuZhou%'

 

2.查询数据库表大小

复制代码
 1 if exists(select 1 from tempdb..sysobjects where id=object_id('tempdb..#tabName') and xtype='u')
 2 drop table #tabName
 3 go
 4 create table #tabName(
 5 tabname varchar(100),
 6 rowsNum varchar(100),
 7 reserved varchar(100),
 8 data varchar(100),
 9 index_size varchar(100),
10 unused_size varchar(100)
11 )
12  
13 declare @name varchar(100)
14 declare cur cursor for
15 select name from sysobjects where xtype='u' order by name
16 open cur
17 fetch next from cur into @name
18 while @@fetch_status=0
19 begin
20     insert into #tabName
21     exec sp_spaceused @name
22     --print @name
23  
24     fetch next from cur into @name
25 end
26 close cur
27 deallocate cur
28 
29 select tabname as '表名',rowsNum as '表数据行数',reserved as '保留大小',data as '数据大小',index_size as '索引大小',unused_size as '未使用大小'
30 from #tabName
31 order by tabname asc, data desc
复制代码

 

posted @   李文学  阅读(1103)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示