x
login about faq Site discussion (meta-askssc)

How do I determine what filegroup my partition data is stored in?

Seeder question: I have a table whose clustered index is created on a partition scheme - how do I determine what file group each partition is stored in using a query? It needs to be a query rather than referencing the DDL because the information is needed for a space report.

more ▼

asked Oct 27 '09 at 06:57 PM in Default

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.2k 56 63 87

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

This turned out to be tougher than I thought it would. I had to do some serious BOL research to figure out the connection (sys.allocation_units). I decided to include the approximate number of rows from sys.partitions as some extra information.

DECLARE @TableName sysname = 'MyTable';

SELECT p.partition_number, fg.name, p.rows
FROM sys.partitions p
    INNER JOIN sys.allocation_units au
    ON au.container_id = p.hobt_id
    INNER JOIN sys.filegroups fg
    ON fg.data_space_id = au.data_space_id
WHERE p.object_id = OBJECT_ID(@TableName)
more ▼

answered Oct 28 '09 at 12:12 AM

Tom Staab gravatar image

Tom Staab
5.8k 5 8 10

Yeah, it's not as easy as you might think! You can also go from sys.indexes -> sys.partition_schemes -> sys.destination_data_spaces -> sys.filegroups but that method is even less obvious! :)

Oct 28 '09 at 07:43 AM Matt Whitfield ♦♦
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x914
x46
x24

asked: Oct 27 '09 at 06:57 PM

Seen: 6457 times

Last Updated: Oct 27 '09 at 06:57 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.