Populating a Primary Key Using a Sequence
Sequences are useful for populating integer primary key column values.
SQL> CREATE TABLE emp (
2 id INTEGER CONSTRAINT my_pk1 PRIMARY KEY
3 );
Table created.
SQL>
SQL> CREATE SEQUENCE my_sql NOCACHE;
Sequence created.
SQL>
SQL> INSERT INTO emp (id) VALUES (my_sql.nextval);
1 row created.
SQL> INSERT INTO emp (id) VALUES (my_sql.nextval);
1 row created.
SQL>
SQL> SELECT *
2 FROM emp;
ID
----------
1
2
SQL>
Home »
Oracle »
Table »
Oracle »
Table »
Sequence:
- Creating a Sequence
- Retrieving Information on Sequences
- Using a Sequence
- Populating a Primary Key Using a Sequence
- Modifying a Sequence
- Using Sequences in PL/SQL
- Dropping a Sequence
Related: