Create table with Auto sequence in Oracle 12c
HappyCode 0002 : Create table with Auto sequence in Oracle 12c
Starting from oracle 12, we can begin to define the column of a table as an auto increment sequence directly as part of the table itself.
Syntax shown as below :
GENERATED
[ ALWAYS | BY DEFAULT [ ON NULL ] ]
AS IDENTITY [ ( identity_options ) ]
For this case, we will use the IDENTITY AS ALWAYS option :
CREATE TABLE demo_auto_seq_always (
id NUMBER GENERATED ALWAYS AS IDENTITY START WITH 100 INCREMENT BY 1,
object_name VARCHAR2(255) NOT NULL
);
In this table, we can see the value of the "ID" column being filled in automatically, starting at 100 with increment by 1.
We can use this query to find information about the IDENTITY column, by using the view "all_tab_identity_cols"
Github : https://github.com/happycodingkoe/database_oracle/tree/master/Readmeshare_0002_ORA_AutoSeqAlwaysTable
Blog : https://happycodingkoe.blogspot.com/
IG : @happycodingkoe
FB : https://web.facebook.com/happycoding.koe.3
Starting from oracle 12, we can begin to define the column of a table as an auto increment sequence directly as part of the table itself.
Syntax shown as below :
GENERATED
[ ALWAYS | BY DEFAULT [ ON NULL ] ]
AS IDENTITY [ ( identity_options ) ]
For this case, we will use the IDENTITY AS ALWAYS option :
CREATE TABLE demo_auto_seq_always (
id NUMBER GENERATED ALWAYS AS IDENTITY START WITH 100 INCREMENT BY 1,
object_name VARCHAR2(255) NOT NULL
);
In this table, we can see the value of the "ID" column being filled in automatically, starting at 100 with increment by 1.
We can use this query to find information about the IDENTITY column, by using the view "all_tab_identity_cols"
Github : https://github.com/happycodingkoe/database_oracle/tree/master/Readmeshare_0002_ORA_AutoSeqAlwaysTable
Blog : https://happycodingkoe.blogspot.com/
IG : @happycodingkoe
FB : https://web.facebook.com/happycoding.koe.3
Komentar
Posting Komentar