SQL statistics on which tables use partition tables

Source: Internet
Author: User

Select object_name (P. object_id) as objectname,
I. Name as indexname,
P. index_id as indexid,
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 range,
P. rows as rows
From SYS. partitions as P
Join SYS. indexes as I
On I. object_id = P. object_id
And I. index_id = P. 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
Where
Objectproperty (P. object_id, 'ismsshipped ') = 0
Union all

-- Non-partitioned table/Indexes

Select
Object_name (P. object_id) as objectname,
I. Name as indexname,
P. index_id as indexid,
Null as partitionscheme,
P. partition_number as partitionnumber,
FG. Name as filegroupname,
Null as lowerboundaryvalue,
Null as upperboundaryvalue,
Null as boundary,
P. rows as rows
From SYS. partitions as P
Join SYS. indexes as I
On I. object_id = P. object_id
And I. index_id = P. index_id
Join SYS. data_spaces as DS
On Ds. data_space_id = I. data_space_id
Join SYS. filegroups as FG
On FG. data_space_id = I. data_space_id
Where
Objectproperty (P. object_id, 'ismsshipped ') = 0
Order
Objectname,
Indexid,
Partitionnumber;

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/htl258/archive/2009/04/20/4095110.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.