DM模式对象
DM模式对象包括表、视图、索引、触发器等,下面将对这些模式对象的基本操作进行展示。
1.表
DM中支持的表包括普通表,分区表,列存表,对象表,临时表,外部表等,这里基于普通表和分区表进行操作.
1.1普通表
DM中支持创建/查询/删除普通行存表,支持自增列,检查约束,非空约束,缺省值等的设置.
1.1.1创表
首先创建一个普通行存表test,设置主键自增,非空约束,检查约束等.
create table test(
id int primary key identity(1,1),
name varchar(10) not null,
sex char(2) check(sex='男'or sex='女') not null,
grade decimal,
height decimal(4,1) not null,
weight double not null,
birth date not null
)
1.1.2插入数据
插入符合约束条件的数据:
insert into test values('张三','男',88.8,166.6,80,'1998-1-1');
insert into test values('李四','男',88,166.6,85.5,'1998-2-2');
insert into test values('王五','男',66.666,166.67,75.5,'1998-3-3');
insert into test values('王芳','女',88,166,65,'1998-4-4');
接着插入不符合约束条件的数据,会报错,显示相应的错误信息:
insert into test values('赵六','无',null,175.68,80,'1998-1-1');
insert into test values('赵六','男',null,null,80,'1998-1-1');
1.1.3删除表
使用命令drop table [表名]进行删除:
drop table test;
1.2分区表
DM中支持各种类型的分区表,如范围分区表,哈希分区表,列表分区表以及组合分区表.
1.2.1范围分区表
创建范围分区表的语法如下:
create table callinfo(
caller char(15),
callee char(15),
time datetime,
duration int
)
partition by range(time)(
partition p1 values less than('2020-04-01'),
partition p2 values less than('2020-07-01'),
partition p3 values less than('2020-10-01'),
partition p4 values equ or less than(maxvalue)
);
范围分区表增加分区:
在范围分区表增加分区的时候,要注意如果设置的范围值由以maxvalue为上限的分区,要先将此分区删除,才能够成功的增加分区.例如:
范围分区表增加分区:
alter table callinfo add partition p5 values less than('2020-12-31');
将显示错误:
删除范围分区表中范围为max value的分区:
alter table callinfo drop partition p4;
再次增加分区,就可以成功添加分区:
alter table callinfo