3

데이터베이스에 액세스 할 수 있으며 데이터베이스의 파티션 구성표 정의를 알아야합니다. 즉, 파티션 구성표 이름, 사용중인 파티션 구성표, 할당 된 파일 그룹 등을 알 필요가 있습니다.SQL Server 데이터베이스에서 파티션 스키마 정의 찾기

예를 들어 누군가가 파티션 구성표를 작성합니다 (msdn에서 가져옴) :

myRangePS1, 기능 : myRangePF1, 및 파티션 : 그것은 파티션 ALL 여부

이 있는지 여부 (test1fg, test2fg, test3fg, test4fg), 어떻게 것

CREATE PARTITION SCHEME myRangePS1 
AS PARTITION myRangePF1 
TO (test1fg, test2fg, test3fg, test4fg); 

은 그 때 나는 이름 합니다 SQL 문을 사용하여 이것에 관해서 만? sys.partition_scheme 시스템 뷰를 사용하여 파티션에 대한 이름과 일부 데이터를 쿼리 할 수는 있지만 충분하지 않습니다. http://social.msdn.microsoft.com/forums/sqlserver/en-US/d0ce92e3-bf48-455d-bd89-c334654d7e97/how-to-find-partition-function-text-applied-to-a-table

답변

9

내가 수정 한 knkarthick24의 첫 번째 쿼리는 각 파일 그룹에 관련된 파티션 함수 값을 표시합니다 :

select distinct ps.Name AS PartitionScheme, pf.name AS PartitionFunction,fg.name AS FileGroupName, rv.value AS PartitionFunctionValue 
    from sys.indexes i 
    join sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id 
    join sys.partition_schemes ps on ps.data_space_id = i.data_space_id 
    join sys.partition_functions pf on pf.function_id = ps.function_id 
    left join sys.partition_range_values rv on rv.function_id = pf.function_id AND rv.boundary_id = p.partition_number 
    join sys.allocation_units au ON au.container_id = p.hobt_id 
    join sys.filegroups fg ON fg.data_space_id = au.data_space_id 
where i.object_id = object_id('TableName') 

이 내가 찾고있는 쿼리가 내가 다른 사람이 사용을 할 수 있기를 바랍니다!

2

이 쿼리 시도하십시오 :

select ps.Name AS PartitionScheme, pf.name AS PartitionFunction,fg.name AS FileGroupName 
    from sys.indexes i 
    JOIN sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id 
    join sys.partition_schemes ps on ps.data_space_id = i.data_space_id 
    join sys.partition_functions pf on pf.function_id = ps.function_id 
    join sys.allocation_units au ON au.container_id = p.hobt_id 
    join sys.filegroups fg ON fg.data_space_id = au.data_space_id 
    where i.object_id = object_id('TableName') 

이상의 자세한 정보는 1)

은 아래의 쿼리를 사용합니다 (SQL

아래는 파티션 기능의 정의를 찾는 유사한 솔루션을 보여줍니다 2008 내부 구조 책)

2)

SELECT 
ISNULL(quotename(ix.name),'Heap') as IndexName 
,ix.type_desc as type 
,prt.partition_number 
,prt.data_compression_desc 
,ps.name as PartitionScheme 
,pf.name as PartitionFunction 
,fg.name as FilegroupName 
,case when ix.index_id < 2 then prt.rows else 0 END as Rows 
,au.TotalMB 
,au.UsedMB 
,case when pf.boundary_value_on_right = 1 then 'less than' when pf.boundary_value_on_right is null then '' else 'less than or equal to' End as Comparison 
,fg.name as FileGroup 
,rv.value 
FROM sys.partitions prt 
inner join sys.indexes ix 
on ix.object_id = prt.object_id and 
ix.index_id = prt.index_id 
inner join sys.data_spaces ds 
on ds.data_space_id = ix.data_space_id 
left join sys.partition_schemes ps 
on ps.data_space_id = ix.data_space_id 
left join sys.partition_functions pf 
on pf.function_id = ps.function_id 
left join sys.partition_range_values rv 
on rv.function_id = pf.function_id AND 
rv.boundary_id = prt.partition_number 
left join sys.destination_data_spaces dds 
on dds.partition_scheme_id = ps.data_space_id AND 
dds.destination_id = prt.partition_number 
left join sys.filegroups fg 
on fg.data_space_id = ISNULL(dds.data_space_id,ix.data_space_id) 
inner join (select str(sum(total_pages)*8./1024,10,2) as [TotalMB] 
,str(sum(used_pages)*8./1024,10,2) as [UsedMB] 
,container_id 
from sys.allocation_units 
group by container_id) au 
on au.container_id = prt.partition_id 
WHERE prt.OBJECT_ID = object_id(N'dbo.test') 
order by ix.type_desc; 
,451,515,
+0

안녕하세요. 첫 번째 쿼리는 파티션 함수 섹션이 어느 파일 그룹에 속했는지에 대한 정보가 누락되었지만 두 번째 쿼리에는이 정보가 있습니다 –

관련 문제