4

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.

2
  • Well there's definitely a better way than 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. Commented Mar 4, 2013 at 19:04
  • Another sp_MsForEachdb replacement, with no cursors this time: spaghettidba.com/2011/09/09/a-better-sp_msforeachdb Commented Mar 4, 2013 at 22:44

1 Answer 1

2

Sorry. Afraid not. you have to query sys.filegroups and/or sys.data_spaces in each database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.