How to partition a Azure SQL server table and repartition automatically?

mrwjdhj3  于 2023-06-21  发布在  SQL Server
关注(0)|答案(1)|浏览(147)

I am learning Data Engineering on Azure. While learning about Azure SQL server, while learning about partitioning, I saw that partitioning SQL Server table is very different from other like in Bigquery or in Oracle.

Can anyone explain me how to create a partition table in Azure SQL Server. And , once the range for partition is reached,how we can automatically add new range in partition?

For example, if table is partitioned on Column Order_Year, and currently have values from 2015-2020. If I got a new value for that column, like 2021, how we can automatically add that partition to partition range?

f45qwnt8

f45qwnt81#

To create partition table you should use partiotion function. Define partiotion function with range

CREATE  PARTITION  FUNCTION pf_OrderYear (INT)
AS  RANGE  RIGHT  FOR  VALUES (2015, 2016, 2017, 2018, 2019, 2020);

Create partition scheme

CREATE  PARTITION  SCHEME ps_OrderYear
AS  PARTITION pf_OrderYear
ALL  TO ('PRIMARY') ;

Create table with create table command with the partition scheme specified.

CREATE  TABLE PartitionedTable
(
   ID INT,
  Order_Year INT
)
ON ps_OrderYear(Order_Year);

To add new range you can use alter partition function.

ALTER PARTITION FUNCTION pf_OrderYear()
SPLIT RANGE (2021);

相关问题