Take the 2-minute tour ×
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. It's 100% free, no registration required.

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. sqlblog.com/blogs/aaron_bertrand/archive/2010/12/29/… 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.com/2011/09/09/a-better-sp_msforeachdb –  spaghettidba Mar 4 '13 at 22:44
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.