序列对象
序列对象产生整个数据库的一个唯一值。跟标识列不一样的是,序列独立于数据表:
CREATE TABLE t1 (salary int)
CREATE SEQUENCE myseq
START WITH 10
INCREMENT BY 1
NO CYCLE
INSERT INTO t1 VALUES (nextval for myseq)
INSERT INTO t1 VALUES (nextval for myseq)
INSERT INTO t1 VALUES (nextval for myseq)
SELECT * FROM t1
SALARY
-----------
10
11
12
3 record(s) selected.
SELECT prevval for myseq FROM sysibm.sysdummy1
SELECT nextval for myseq FROM sysibm.sysdummy1