我如何获得sp_spaceused的database_size值?

时间:2019-01-24 08:44:22

标签: sql-server azure-sql-data-warehouse

我正在尝试获取SQL Server(数据仓库)的database_size值

据我所知,我们已经使用sp_spaceused来检查database_size

但是我找不到任何解决方案来帮助grep database_size值的数量

另一个解决方案是不使用空间,但是由于Azure DWH不允许sys.master_file,所以其他解决方案也无法使用。

任何帮助将不胜感激!

3 个答案:

答案 0 :(得分:0)

当您运行查询EXEC sp_helpdb时,您将获得整个数据库的大小。您还可以在此处传递任何特定的数据库名称。无论您当前在哪个数据库中。

答案 1 :(得分:0)

答案 2 :(得分:0)

尝试

declare @dbsize as bigint
declare @logsize as bigint

select 
  @dbsize = sum(convert(bigint,case when status & 64 = 0 then size else 0 end))
, @logsize = sum(convert(bigint,case when status & 64 <> 0 then size else 0 end))
from dbo.sysfiles;

select dbSizeInMB = cast((@dbsize + @logsize)*8/1024.0  AS decimal(10,2) );