标签:
分区表和partition scheme之间的关系是由sys.indexes 确定的,当index_id=0,表示分区表是个heap,表没有创建聚集索引,当index_id=1,表示分区表是个BTree,表存在聚集索引。
sys.indexes Contains a row per index or heap of a tabular object, such as a table, view, or table-valued function.
sys.indexes 有一个非常关键的字段 data_space_id
ID of the data space for this index. Data space is either a filegroup or partition scheme.
0 = object_id is a table-valued function.
Script1,查询DB中表所使用的Partition Scheme 和 Partition Function
select distinct i.object_id, object_name(i.object_id) as ObjectName, ps.Name AS PartitionScheme, pf.name AS PartitionFunction from sys.indexes i inner join sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id inner join sys.partition_schemes ps on ps.data_space_id = i.data_space_id inner join sys.partition_functions pf on pf.function_id = ps.function_id where i.index_id<=1 --and i.object_id = object_id(‘dbo.FactThread‘)
Script2,查看某一个表分区的详细情况
select distinct i.object_id, object_name(i.object_id) as ObjectName, ps.Name AS PartitionScheme, pf.name AS PartitionFunction, fg.name AS FileGroupName, rv.value AS PartitionFunctionValue from sys.indexes i inner join sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id inner join sys.partition_schemes ps on ps.data_space_id = i.data_space_id inner 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 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 i.index_id<=1 and i.object_id =object_id(‘dbo.dtThread‘)
Appendix
在使用Object_ID() 获取table的object_id时,推荐使用two part 命名方式:schema_name . table_name
When a temporary table name is specified, the database name must come before the temporary table name, unless the current database is tempdb. For example: SELECT OBJECT_ID(‘tempdb..#mytemptable‘).
查看分区表使用的partition scheme 和 partition function
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/5072760.html