Differences between Oracle and Mysql auto growing columns of id

  • 2021-11-01 05:21:44
  • OfStack

The automatic growth column mentioned here mainly refers to the automatic growth of the primary key id in a table.

Unlike Mysql, Oracle cannot set the auto-growing column function when CREATE creates a table.

Oracle must automatically add columns by creating an sequence sequence.

First, the sequence must be created (of course, the table must be built first, and the primary key constraint must be added. This column assumes that the constraint is named test_sequence)

create sequence test_sequence
[increment by 1]--Step Size of Growth
[start with 1]--Growing since
[maxvalue 100]--Maximum growth
[nomaxvalue]--No Maximum
[cyclenocycle]; -Cyclic growth/non-cyclic growth

Once sequence is defined, you can use test_sequence. nextval and test_sequence. currval in the insert statement.
test_sequence. currval returns the value of the current sequence, but test_sequence. currval cannot be used until test_sequence. nextval is initialized for the first time.
test_sequence. nextval increments the value of sequence and returns the increased value of sequence.

The sequence sequence can then be modified by alter to change the way of automatic increment.
alter sequence test_sequence increment by 1...; The following options are the same as when building a table.

You can also delete the sequence sequence with drop.
drop sequence test_sequence;

Mysql is much simpler for Oracle first, and can be set up when building tables.


create table( id int(10) auto_increment primary key) auto_increment=1;

auto_increment=1 Sets the auto-growing column to start at 1


Related articles: