目的:
测试分区表数据插入效果
思路:
在Music数据库里创建一个分区表,表名music,按照业务逻辑分为4个分区,分别叫做P1、P2、P3和P4,本次试验中插入2条数据,一条是摇滚歌曲的信息,另一条是流行歌曲的信息,分别插入到P1和P2中,最后验证插入效果。
db2 => connect to music
Database Connection Information
Database server = DB2/LINUXX8664 10.5.5
SQL authorization ID = DB2INST1
Local database alias = MUSIC
数据库里没有任何表:
db2 => list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
0 record(s) selected.
创建分区表:
db2 => create table music(id integer,name varchar(20),style varchar(20),style_code integer) partition by range(style_code) (part p1 starting '1',part p2 starting '2',part p3 starting '3',part p4 starting '4' ending maxvalue)
DB20000I The SQL command completed successfully.
检验是否以创建好表:
db2 => list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
MUSIC DB2INST1 T 2015-07-03-00.42.20.180544
1 record(s) selected.
插入两条歌曲信息:
db2 => insert into music values(1,'Have a Nice Day','pop',2)
DB20000I The SQL command completed successfully.
db2 => insert into music values(2,'We will rock you','rock',1)
DB20000I The SQL command completed successfully.
查看表结构相关信息,可以看到4个分区的信息:
db2 => describe data partitions for table music show detail
PartitionId PartitionName TableSpId PartObjId IndexTblSpId LongTblSpId AccessMode
Status
----------- ------------------------------- ----------- ----------- ------------ ----------- - ------
0 P1 2 4 2 2 F
1 P2 2 5 2 2 F
2 P3 2 6 2 2 F
3 P4 2 7 2 2 F
4 record(s) selected.
经验证,可以看到P1、P2的分区中,平均表长度均增加,说明信息已存入表中。
db2 => select datapartitionname,tabname,AVGROWSIZE from syscat.datapartitions where tabname = 'MUSIC'
DATAPARTITIONNAME TABNAME AVGROWSIZE
----------------------------- -------------------
P1 MUSIC 50
P2 MUSIC 48
P3 MUSIC 0
P4 MUSIC 0
4 record(s) selected.