I have a data set pulled from sys.master_files
. The data set looks something like this:
database_id filename physical_name data_space_id
----------- ---------------- ------------- -------------
6 PRIMARY_06 some location 1
6 primary_09 some location 1
21 PRIMARY_01 some location 1
26 PRIMARY_01 some location 1
52 PRIMARY_01 some location 1
75 PRIMARY_01 some location 1
I would like to join in the FILEGROUP name to this dataset. It should just be a matter of joining on database_id
and data_space_id
, but I can't seem to find a function or system view analogous to sys.master_files
for filegroups/dataspaces.
The brute force method would be to create this list as a temporary lookup using sp_MSForEachDB
, but I would like to know if there's a better way.
sp_MSforeachdb
. sqlblog.org/2020/08/04/… It's also trivial to write your own dynamic SQL that unions the output of the filegroup information from each database. You could also create a view that looks like a catalog view and performs this union manually - feasibility depends I guess on how often you add/drop databases.