首先呢我们来看下怎么创建一个分区表
在上节课的时候 我们也说过 在分区的时候
如果分区字段中有主键或者唯一索引的列,那么多有主键列和唯一索引列都必须包含进来。
1 ,按照年龄的范围
create table staff_r12(
id int not null auto_increment,
name varchar(40) not null,
age int not null,
primary key (id
,age
)
)engine=myisam default charset=utf8
partition by range(age)(
partition age_1 values less than(20),
partition age_2 values less than(40),
partition age_3 values less than maxvalue
);
2,按照时间戳timestamp范围来分区
create table staff_r13(
id int not null,
staff_status varchar(20) not null,
report_updated timestamp not null default current_timestamp on update current_timestamp
)
partition by range(unix_timestamp(report_updated))(
partition p0 values less than (unix_timestamp(‘2008-01-01 00:00:00’)),
partition p1 values less than (unix_timestamp(‘2008-04-01 00:00:00’)),
partition p2 values