SQL SERVER- partition table

 

 

 

 

 

 

 

- Create a partition function 
the CREATE PARTITION FUNCTION parfn_Date (a Date)
 AS RANGE   RIGHT  
the FOR  VALUES ( ' 2019-05-01 ' , ' 2019-06-01 ' ) 

- to view the partition function of 
the SELECT   *   the FROM   SYS.PARTITION_FUNCTIONS 

- Create a partition scheme 
the CREATE pARTITION SCHEME sch_parfn_Date
 AS pARTITION parfn_Date
  the TO ( [ Primary ] , FG1, fg2) 

 - View partitioning scheme 
 the SELECT   *   the FROM  SYS.PARTITION_schemes


 --创建分区表
  CREATE  TABLE  shipment_header
 (
     [CustomerID] [varchar](20) NOT NULL,
    [SAPSoldTo] [varchar](20) NOT NULL,
    [ShipmentNo] [varchar](20) NOT NULL,
    [Shipmark] [varchar](20 is ) NULL ,
     [ the ShipDate ] a Date NULL , 

 ) the ON   sch_parfn_Date ( [ the ShipDate ] )
  - Specifies the architecture and partitioning column, the column data type to the partition and the partition function of the same type of parameters 


 - see the partition table data distribution 
 SELECT  Convert ( VARCHAR ( 50 ), ps.name) AS partition_scheme, 
p.partition_number, 
Convert ( VARCHAR ( 10 ), ds2.name) AS filegroup, 
 Convert ( VARCHAR ( . 19 ),isnull(v.value, ''), 120) as range_boundary, 
str(p.rows, 9) as rows
from sys.indexes i 
join sys.partition_schemes ps on i.data_space_id = ps.data_space_id 
join sys.destination_data_spaces dds
on ps.data_space_id = dds.partition_scheme_id 
join sys.data_spaces ds2 on dds.data_space_id = ds2.data_space_id 
join sys.partitions p on dds.destination_id = p.partition_number
and p.object_id = i.object_id and p.index_id = i.index_id 
join sys.partition_functions pf on ps.function_id = pf.function_id 
LEFT JOIN sys.Partition_Range_values v on pf.function_id = v.function_id
and v.boundary_id = p.partition_number - pf.boundary_value_on_right 
WHERE i.object_id = object_id('SHIPMENT_HEADER')
and i.index_id in (0, 1) 
order by p.partition_number

 

 

Reference: https://www.cnblogs.com/CareySon/archive/2011/12/30/2307766.html

Guess you like

Origin www.cnblogs.com/JinweiChang/p/11226785.html