Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3061142
  • 博文数量: 206
  • 博客积分: 3409
  • 博客等级: 中校
  • 技术积分: 4066
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 10:21
个人简介

● ITPUB名人堂嘉宾 ● ChinaUnix社区博客专家 ● ChinaUnix社区Oracle板块版主 ● 优酷网认证音乐牛人:EricGuitar ● SDOUG 核心成员 ●E-mail:gaoqiangdba@163.com

文章分类

全部博文(206)

文章存档

2021年(11)

2020年(7)

2019年(7)

2016年(5)

2015年(36)

2014年(23)

2013年(15)

2012年(23)

2011年(61)

2010年(18)

分类: DB2/Informix

2015-07-13 10:15:27

  



目的:
测试分区表数据插入效果

思路:
在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.


阅读(7340) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~