简体   繁体   English

SQL Server 2014 Express上的可用空间

[英]Free space on SQL Server 2014 Express

Since the Express edition is limited to 10 GB (couldn't figure out if it was 'per database' or as a whole since the documentation is confusing,well at least for me), I am wondering is there a way to check this space availability ie how much have I used so far ? 由于Express版本限制为10 GB(至少是对我来说,由于文档令人困惑,所以无法确定是“每个数据库”还是整个数据库),我想知道是否有办法检查此空间可用性,即到目前为止我用了多少? I used some suggestions from the internet but somehow not all of my databases show up. 我使用了互联网上的一些建议,但并非所有数据库都以某种方式出现。

The 10 GB is for data file size. 10 GB用于数据文件大小。 You can get percentage used of each file like this: 您可以像这样获取每个文件的使用百分比:

;WITH x AS 
(
  SELECT name, [file] = physical_name, size = size * 8, 
    su_bytes = FILEPROPERTY(name, 'SpaceUsed') * 8
  FROM sys.database_files
)
SELECT name, [file], size, SpaceUsed = su_bytes,
  [SpaceUsed%] = CONVERT(DECIMAL(5,2), su_bytes*100.0/size)
FROM x;

As follows from the manual on sys.database_files , the size column holds the size expressed in 8K pages, hence multiplying the value by 8 gives you the size in kilobytes. sys.database_files手册中所述, size列保存以8K页表示的大小,因此将值乘以8可得到以千字节为单位的大小。 Same applies to the result of FILEPROPERTY(..., 'SpaceUsed') . 同样适用于FILEPROPERTY(..., 'SpaceUsed') To obtain the amounts in other units, change the calculations accordingly. 要获得其他单位的金额,请相应地更改计算。

You're right ... Did some googling and found a much better solution: 您是对的...做了一些谷歌搜索,发现了一个更好的解决方案:

SELECT name AS 'File Name' , physical_name AS 'Physical Name', size/128 AS 'Total Size in MB',

size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS 'Available Space In MB', *

FROM sys.database_files;

even better : 更好:

SELECT DB_NAME(A.DATABASE_ID) AS DBNAME,A.NAME AS FILENAME ,

SIZE/128.0 AS CURRENTSIZE_MB,

B.RECOVERY_MODEL_DESC,A.TYPE_DESC ,

CASE WHEN IS_PERCENT_GROWTH = 0

THEN LTRIM(STR(A.GROWTH * 8.0 / 1024,10,1)) + ' MB, '

ELSE 'BY ' + CAST(A.GROWTH AS VARCHAR) + ' PERCENT, 'END +

CASE WHEN MAX_SIZE = -1 THEN 'UNRESTRICTED GROWTH'

ELSE 'RESTRICTED GROWTH TO ' +LTRIM(STR(MAX_SIZE * 8.0 / 1024,10,1)) + ' MB'

END AS AUTOGROW,A.PHYSICAL_NAME

FROM SYS.MASTER_FILES A JOIN SYS.DATABASES B

ON A.DATABASE_ID =B.DATABASE_ID

--WHERE A.PHYSICAL_NAME LIKE 'E%'

-- AND A.FILE_ID =2

ORDER BY A.SIZE/128.0 DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM