LiCongMingDeShujuku / Get-All-Database-Sizes-in-GB--Data--Log--and-Total--Rounded

获取大小以GB(数据,日志和总计)为单位的所有数据库大小

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLEVER DATA GIT REPO

获取大小以GB(数据,日志和总计)为单位的所有数据库大小

Get All Database Sizes in GB (Data, Log, and Total) Rounded

发布-日期: 2015年08月19日 (评论)

#

Contents

中文

这里有一些SQL逻辑基本上会以GB为单位提供数据,日志和总数(数据+日志)。另外,所有尺寸均为圆形(天花板)。

用于引用的总计的SQL逻辑需要注意:1GB内的差异舍入为1GB,如果找到的差异少于1GB,则数据和日志文件之间的总数不会超过1GB。

English

Here’s some SQL logic that will basically give you the data, log, and total (data + log) in GB. Additionally; all sizes are rounded (ceiling).

SQL logic for totals for reference Note: Variances within 1GB are rounded as 1GB and totals between data & log files will not exceed 1gb if fewer than 1GB variances are found.


Logic

use master;
set nocount on
select
[name] = upper(sd.name)
,   [data   - in gb]    = ceiling(sum(case when type = 0 then (smf.size*8)/1024.0/1024.0 else 0 end))
,   [log    - in gb]    = ceiling(sum(case when type = 1 then (smf.size*8)/1024.0/1024.0 else 0 end)) , [total  - in gb]    = ceiling(sum(smf.size * 8.00/1024.00/1024.00)) from
sys.databases sd join sys.master_files smf on sd.database_id = smf.database_id where
sd.source_database_id is null
and sd.name not in ('master', 'model', 'msdb', 'tempdb')
group by
sd.name
order by
[data   - in gb] desc

WorksEveryTime

Build-Info

Build Quality Build History
Build-Status
Coverage
Nuget
Build history

Author

  • 李聪明的数据库 Lee's Clever Data
  • Mike的数据库宝典 Mikes Database Collection
  • 李聪明的数据库 "Lee Songming"

Gist Twitter Wordpress


License

LicenseCCSA

Lee Songming

About

获取大小以GB(数据,日志和总计)为单位的所有数据库大小