Definition and use of sequence in DB2

Source: Internet
Author: User

Definition and use of sequence in DB2

-- Method 1 (self-used, green, secure, and pollution-free): Create a sequence named SEQ_LDBG, auto-increment 1, create sequence SEQ_LDBG as int start with 1 increment by 1 MINVALUE 1 no maxvalue no cycle no cache order; -- use nextval for SEQ_LDBG in SQL, codechange7 is the table name, select nextval for SEQ_LDBG, code, name from codechange7; --- Method 2: create sequence SEQ_LDBG start with 1 increment by 1 nomaxvalue nocycle cache 24; -- Get the next value select nextval for SEQ_LDBG from codechange7; -- get the current value select prevval for SEQ_LDBG from codechange7; -- insert record insert into codechange7 (id) values (nextval for id) -- delete sequence drop sequence SEQ_LDBG; -- set SEQUENCE start value ALTER sequence SEQUENCE name (SEQ_LDBG) restart with next value (1) -- modify maximum value: alter sequence <sequence_name> max value <numeric-constant> | no maxvalue: alter sequence <sequence_name> min value <numeric-constant> | NO MINVALUE

 

(This value must be smaller than the current value)
Modify the step size: alter sequence <sequence_name> increment by <numeric-constant>; modify the CACHE value: alter sequence <sequence_name> CACHE <numeric-constant> | no cache to modify the loop attribute: alter sequence <sequence_name> <CYCLE | no cycle> modify the sorting attribute: alter sequence <sequence_name> <ORDER | no order> new count: alter sequence <sequence_name> RESTART | restart with <numeric-constant>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.