1.首先,创建sequence
CREATE SEQUENCE SEQ_NAME1
AS Integer 默认 As Integer
START WITH 1
INCREMENT BY 1 默认 INCREMENT BY 1
MINVALUE 1 | NO MINVALUE 默认 NO MINVALUE
MAXVALUE 999 | NO MAXVALUE 默认 NO MAXVALUE
NO CYCLE | CYCLE 默认 NO CYCLE
CACHE 30 | NO CACHE 默认 CACHE 20
NO ORDER | ORDER 默认 NO ORDER
;
2.创建SEQ_TABLE
CREATE TABLE SEQ_TABLE(
SEQ1 Integer;
);
3.关联SEQ_NAME1与SEQ_TABLE
INSERT INTO SEQ_TABLE VALUES(SEQ_NAME1.nextval);
4.使用:
获取下一个值:SELECT SEQ_NAME1.nextval from SEQ_TABLE
删除:DROP SEQUENCE SEQ_NAME1;
修改:
修改最大值: ALTER SEQUENCE SEQ_NAME1 MAX VALUE 9999| NO MAXVALUE
修改最小值: ALTER SEQUENCE SEQ_NAME1 MIN VALUE 10 | NO MINVALUE
修改步长: ALTER SEQUENCE SEQ_NAME1 INCREMENT BY 2;
修改CACHE值: ALTER SEQUENCE SEQ_NAME1 CACHE 40 | NO CACHE
修改循环属性: ALTER SEQUENCE SEQ_NAME1 <CYCLE | NO CYCLE>
修改排序属性:ALTER SEQUENCE SEQ_NAME1 <ORDER | NO ORDER>
从新计数: ALTER SEQUENCE SEQ_NAME1 RESTART | RESTART WITH 2