Database self-increment implementation

Source: Internet
Author: User

MySQL adds auto_increment directly behind the field

Oracle

The main point is 2, the first is to create a sequence name sequence;
Then, when the INSERT statement is placed: the position of the Increment field, written as the sequence name. Nextval.

As explained below, starting with creating a table and then creating a sequence, how to write the INSERT statement, you can implement the field's self-increment process.

1. Create a table first

CREATE TABLE "flowcal". "T_userinfo "
( "c_id "Number (*,0),
"C_user" VARCHAR2 (BYTE),
"C_password" VARCHAR2 (BYTE),
"C_role" VARCHAR2 (BYTE),
"C_comment1" VARCHAR2 (BYTE),
"C_comment2" VARCHAR2 (BYTE)
)
Now I want to make c_id a self-increment.


2. First create an Oracle SEQUENCE,SQL statement as follows:
Create sequence sequence name
Increment by 1
Start with 1
MaxValue 999999999
Cycle
Set up a sequence with a minimum of 1 and a serial number with a maximum of 999999999 to be automatically looped


Here is my sequence, as follows:
CREATE SEQUENCE"Flowcal". " Seq_userinfo "
MINVALUE 0
MAXVALUE 999999999999999999999999 9999
increment by 1
start with 24
cache 20
cycle;
3. sequence name. nextval sql> insertinto table name values (, column 1 value, column 2 value,....);

Here's my insert statement:
INSERT into t_userinfo values (seq_userinfo. Nextval , ' 111 ', ' one ', ' one ', ' one ', ' one ')

below is an image For reference:

Database self-increment implementation

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.