创建新分段表

要创建分段表,请使用 CREATE TABLE 语句的 FRAGMENT BY 子句。假定您想要创建与 stores_demo 数据库的 orders 表相类似的分段表。您决定使用具有三个分段的循环分布方案,并向数据库服务器管理员咨询以设置三个数据库空间(为每个分段设置一个):dbspace1、dbspace2 和 dbspace3。以下 SQL 语句创建分段表:
CREATE TABLE my_orders (
      order_num      SERIAL(1001),
      order_date     DATE,
      customer_num   INT, 
      ship_instruct  CHAR(40),
      backlog        CHAR(1),
      po_num       CHAR(10),
      ship_date    DATE,
      ship_weight  DECIMAL(8,2),
      ship_charge  MONEY(6),
      paid_date    DATE,
      PRIMARY KEY (order_num),
      FOREIGN KEY (customer_num) REFERENCES customer(customer_num))
      FRAGMENT BY ROUND ROBIN IN dbspace1, dbspace2, dbspace3

或者,您也可以决定使用基于表达式的分段存储来创建表。假定 my_orders 表有 30000 行,并且您想对三个存储在 dbspace1、dbspace2 和 dbspace3 中的分段均匀地分布行。以下语句显示了如何使用 order_num 列来定义基于表达式的分段存储策略:

CREATE TABLE my_orders (order_num SERIAL, ...)
      FRAGMENT BY EXPRESSION
            order_num < 10000 IN dbspace1,
            order_num >= 10000 and order_num < 20000 IN dbspace2, 
            order_num >= 20000 IN dbspace3