您现在的位置是:首页 > 博文答疑 > DB2笔记系列 10 - 索引和序列管理博文答疑

DB2笔记系列 10 - 索引和序列管理

Leo2016-08-22【4】

简介DB2 索引和序列管理

创建索引:

blob.png

blob.png

blob.png

blob.png

blob.png

或者  CREATE UNIQUE INDEX TBLEO01 ON DEPT(C1)


序列自动产生唯一的数值,是一个可共享的对象,通常被用于创建主键值:

序列不能用工具,只能用SPUFI查询:

SELECT * FROM SYSIBM.SYSSEQUENCES;  序列信息。

blob.png

  CREATE TABLE TSLEO.PROD_T(                                          

      ORDER_ID INT NOT NULL,                                          

      ORDER_DATE DATE,                                                

      PRODUCT_ID INT,                                                 

      QUANTITY INT,                                                   

      PRICE DECIMAL(10,2),                                            

      STATUS CHAR(9));                                                

  CREATE SEQUENCE TSLEO.SEQ1                                          

      AS INT                                                          

      START WITH 1                                                    

      INCREMENT BY 1                                                  

      NO MAXVALUE                                                     

      NO CYCLE                                                        

      NO CACHE                                                        

      ORDER;                                                          

  INSERT INTO PROD_T VALUES(NEXT VALUE FOR SEQ1,CURRENT DATE, 001, 100,

  100.50, 'PENDING');  


blob.png

V7下失败:?????????

blob.png

V8下成功:

blob.png

查看插入数据:

blob.png

blob.png


删除序列:

drop sequence seq1 restrict; 

blob.png

blob.png