Differences Between Auto-increment columns (IDS) in Oracle and Mysql

Source: Internet
Author: User
The auto-increment column here mainly refers to the auto-increment of the primary key id in a table. Unlike Mysql, Oracle cannot set the auto-increment column feature when creating a table in CREATE. Else l

The auto-increment column here mainly refers to the auto-increment of the primary key id in a table. Unlike Mysql, Oracle cannot set the auto-increment column feature when creating a table in CREATE. Else l

The auto-increment column here mainly refers to the auto-increment of the primary key id in a table.

Unlike Mysql, Oracle cannot set the auto-increment column feature when creating a table in CREATE.

Oracle must automatically add columns by creating sequence sequences.

First, you must create a sequence. (Of course, you must first create a table and add a primary key constraint. This column assumes the constraint name is test_sequence)

Create sequence test_sequence
[Increment by 1] -- growth step size
[Start with 1] -- Starting from a few times
[Maxvalue 100] -- maximum value of growth
[Nomaxvalue] -- no maximum value

[Cycle | nocycle]; -- cyclic growth/non-cyclic Growth

After sequence is defined, test_sequence.nextval and test_sequence.currval can be used in the insert statement.
Test_sequence.currval returns the value of the current sequence, but test_sequence.currval must be used after test_sequence.nextval is initialized for the first time.
Test_sequence.nextval increases the sequence Value and returns the added sequence value.

Then, you can alter the sequence to change the auto-increment mode.
Alter sequence test_sequence increment by 1.

You can also use drop to delete sequence sequences.
Drop sequence test_sequence;

Mysql is much simpler for Oracle, and can be set during table creation.

Create table (
Id int (10) auto_increment primary key
) Auto_increment = 1;

Auto_increment = 1 Set auto-increment columns to start from 1

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.