美文网首页
【DB2】Partitioning表分区

【DB2】Partitioning表分区

作者: iamsharleen | 来源:发表于2018-10-08 22:25 被阅读0次

    在项目中,我想要往表中插入一条数据,所有学过数据库的人应该都会懂。

    insert into  SS.TABLE(ID,PERIOD,DESC) values(1111,'201808','test');
    

    多简单,是吧。
    然而,死活插不进去!

    The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned:
    
    SQL0327N  The row cannot be inserted into table "SS.TABLE" because it is
    
    outside the bounds of the defined data partition ranges.  SQLSTATE=22525
    

    怎么回事呢?

    关键字:partition,网上一搜,又是一个没接触过的东西——表分区。

    那个这错误什么意思呢?最简单的理解:表里面设置了某种区域限制,我们插入数据不在区域内啊。
    那么,我们要不改一下数据,要不改一下表的限制吧。
    问题又来了,partition range是什么啊?怎么加一个partition?

    先看概念� partitioning是什么东西?
    Table partitioning in DB2 9

    大概了解一下,为了管理一些比较大的表,为了性能好一点,我们把表分成不同的区,每个区有一个自己的范围,数据分配到不同的区里面。
    例如,一个巨大的表,包括了不同年份的数据,我们把年份的字段(YEAR)设置了分区,查询的时候,我们查询2018的数据,那么只需要从包括2018的分区去找就可以了。

    --创建表的时候创建分区
    CREATE TABLE TABLE(...)
    PARTITION BY RANGE(PERIOD)
    ( PART1 STARTING '201801' ENDING '201801',
    PART2 STARTING '201802' ENDING '201802');
    
    --查看表分区
    SELECT datapartitionname, lowvalue, highvalue FROM SYSCAT.DATAPARTITIONS WHERE TABNAME='TABLE';
    
    describe DATA PARTITIONS for table SS.TABLE show detail;
    
    --添加表分区
    alter table TABLE add PARTITION PART8 STARTING '201808' ENDING '201808';
    

    添加一个partition后,成功插入数据!

    先大概这样吧,后面再研究一下。。。

    相关文章

      网友评论

          本文标题:【DB2】Partitioning表分区

          本文链接:https://www.haomeiwen.com/subject/vmcsaftx.html