Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Well there's definitely a better way than sp_MSforeachdb.… 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. – Aaron Bertrand Mar 4 '13 at 19:04
Another sp_MsForEachdb replacement, with no cursors this time: – spaghettidba Mar 4 '13 at 22:44
up vote 2 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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