CREATE TABLE Employees(
Id INT NOT NULL,
Fname VARCHAR(30),
Iname VARCHAR(30),
Hired DATE NOT NULL DEFAULT ‘1990-01-01’,
Separated DATE NOT NULL DEFAULT ‘9999-12-31’,
Job_CODE INT,
Store_ID INT
)
PARTITION BY RANGE(YEAR(Separated ))(
PARTITION S0 VALUESLESS THAN(1991),
PARTITION S1 VALUESLESS THAN(1996),
PARTITION S2 VALUESLESS THAN(2001),
PARTITION S3 VALUESLESS THAN MAXVALUE,
);
CREATE TABLE Employees(
Id INT NOT NULL,
Fname VARCHAR(30),
Iname VARCHAR(30),
Hired DATE NOT NULL DEFAULT ‘1990-01-01’,
Separated DATE NOT NULL DEFAULT ‘9999-12-31’,
Job_CODE INT,
Store_ID INT
)
PARTITION BY LIST(Store_ID)(
PARTITION Snorth VALUESLESS IN(3,5,6,9,17),
PARTITION Seast VALUESLESS IN(1,2,10,11,19,20),
PARTITION Swest VALUESLESS IN(4.12.13.14.18),
PARTITION Scentral VALUESLESS IN (7,8.15.16),
);
CREATE TABLE Employees(
Id INT NOT NULL,
Fname VARCHAR(30),
Iname VARCHAR(30),
Hired DATE NOT NULL DEFAULT ‘1990-01-01’,
Separated DATE NOT NULL DEFAULT ‘9999-12-31’,
Job_CODE INT,
Store_ID INT
)
PARTITION BY HASH(YEAR(Hired))
PARTITIONS 4
;
二.Sql Server
Sql Server在2005之后的版本引入的特性。这个特性允许逻辑上的表在物理上分成多个部分,之前所谓的分区表仅仅是分布式视图,也就是多个表做union视图,而真正的分区表是逻辑上一个表,物理上多个表,原理跟MySql分区表的概念基本一致。有一点值得注意的是分区函数并不具体属于分区架构和分区表,他们之间仅仅属于使用关系。
1).定义分区表首先要定义分区函数,例如:
--创建分区函数
CREATE PARTITION FUNCTION fqPartition(DATE)
AS RANGE RIGHT
FOR VALUES('2010-01-01','2012-01-01')
--查看分区函数是否创建成功
Select * FROM SYS.PARTITION_FUNCTIONSGAI