我在下面有这个查询的这个数据库
SELECT DB_NAME() AS dbname , size/128 AS 'Total Size in MB',
size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS 'Available Space In MB', type,name
FROM sys.database_files;
我想合并数据,以便每个数据库只有 1 行,但会有一个列来计算数据库有多少文件(日志和数据)(下图)
如何在 tempdb 只有 1 行的情况下进行此查询,并将计算数据和日志文件的数量并将其存储在单独的列中?我得到的最接近的是下面的查询,但它是文件类型(日志或数据)的隔离基础。帮助将不胜感激
SELECT DB_NAME() AS dbname, CASE type WHEN 0 THEN 'Data File' WHEN 1 THEN 'Log File' END AS [FileType], COUNT(type) AS [File Count], SUM(size/128) AS 'Total Size in MB',
SUM(size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0) AS 'Available Space In MB'--, *
FROM sys.database_files
WHERE type IN(1,0)
GROUP BY type