I have table that has all the names of the databases that are on a particular server. I want to be able to update the DBSizeMB column with the pertaining DB size.
So far my code is:
DECLARE @DatabaseName VARCHAR(100)
UPDATE master.dbo.mytableName
SET DBsizeMB = (SELECT total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
FROM master.sys.master_files)
WHERE DBSizeMB = NULL
AND DatabaseName = @DatabaseName
Right now the SELECT total size part is summing up all of the databases' sizes.
How can I set it to update each individual database?
master.Utilitiesdatabase for stuff like this, for a start later migratingmasterelsewhere is not (really) possible.