我正在尝试获取SQL Server(数据仓库)的database_size值
据我所知,我们已经使用sp_spaceused来检查database_size
但是我找不到任何解决方案来帮助grep database_size值的数量
另一个解决方案是不使用空间,但是由于Azure DWH不允许sys.master_file,所以其他解决方案也无法使用。
任何帮助将不胜感激!
答案 0 :(得分:0)
当您运行查询EXEC sp_helpdb
时,您将获得整个数据库的大小。您还可以在此处传递任何特定的数据库名称。无论您当前在哪个数据库中。
答案 1 :(得分:0)
您可以使用几个DMV获得此类信息: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-monitoring-with-dmvs https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-db-file-space-usage-transact-sql?view=sql-server-2017
答案 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) );