I am running SQL 2005 SP2.
 I have a partitioned table and was wondering if there is a view that could
 tell me the data that resides on a specific filegroup. What I would like to
 do is to delete only the data that resides on a specific filegroup. Thx.
 --
 Message posted via SQLMonster.com
 http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200802/1Perhaps the $PARTITION() function will help you?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message news:801e77dbe7979@.uwe...
>I am running SQL 2005 SP2.
> I have a partitioned table and was wondering if there is a view that could
> tell me the data that resides on a specific filegroup. What I would like to
> do is to delete only the data that resides on a specific filegroup. Thx.
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200802/1
>|||> I have a partitioned table and was wondering if there is a view that could
> tell me the data that resides on a specific filegroup. What I would like
> to
> do is to delete only the data that resides on a specific filegroup. Thx.
The query below will list partitions by filegroup. You can then delete the
data using $PARTITION function like Tibor mentioned or specify partitioning
column values that map to the partitions on the filegroup. If you have a
lot of data, you might consider switching partitions into a staging table
and then truncating the staging table.
SELECT
 s.name AS SchemaName,
 o.name AS TableName,
 ds.name AS PartitionScheme,
 p.partition_number AS PartitionNumber,
 fg.name AS FileGroupName,
 prv_left.value AS LowerBoundaryValue,
 prv_right.value AS UpperBoundaryValue,
 CASE pf.boundary_value_on_right WHEN 1 THEN 'RIGHT' ELSE 'LEFT' END AS
Boundary,
 p.rows AS Rows
FROM sys.schemas AS s
JOIN sys.objects AS o ON
 o.schema_id = s.schema_id
 AND o.type = 'U'
JOIN sys.indexes AS i ON
 i.object_id = o.object_id AND
 i.index_id IN(0,1)
JOIN sys.partitions p ON
 p.object_id = i.object_id AND
 p.index_id = i.index_id
JOIN sys.data_spaces AS ds ON
 ds.data_space_id = i.data_space_id
JOIN sys.partition_schemes AS ps ON
 ps.data_space_id = ds.data_space_id
JOIN sys.partition_functions AS pf ON
 pf.function_id = ps.function_id
JOIN sys.destination_data_spaces AS dds2 ON
 dds2.partition_scheme_id = ps.data_space_id
 AND dds2.destination_id = p.partition_number
JOIN sys.filegroups AS fg ON
 fg.data_space_id = dds2.data_space_id
LEFT JOIN sys.partition_range_values AS prv_left ON
 ps.function_id = prv_left.function_id
 AND prv_left.boundary_id = p.partition_number - 1
LEFT JOIN sys.partition_range_values AS prv_right ON
 ps.function_id = prv_right.function_id
 AND prv_right.boundary_id = p.partition_number
ORDER BY
 SchemaName,
 TableName,
 FileGroupName,
 PartitionNumber;
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message
news:801e77dbe7979@.uwe...
>I am running SQL 2005 SP2.
> I have a partitioned table and was wondering if there is a view that could
> tell me the data that resides on a specific filegroup. What I would like
> to
> do is to delete only the data that resides on a specific filegroup. Thx.
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200802/1
>
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment