How to create an auto-incrementing primary key in Oracle 1. create a table and set the primary key. 2. create a sequence. 3. create trigger .www.2cto.com. For example: assume that the table name of the data table is tbl_name, the primary key column is tbl_id, and other columns include tbl_name, tbl_age, tbl_xxx .... then CREATE an Oracle SEQUENCE: SQL code CREATE SEQUENCE seq_name -- use the uniform prefix name as much as possible, easy Management of increment by 1 -- Auto INCREMENT step here is set to 1 start with 1 -- count START here is set to 1 NOMAXVALUE -- do not set the maximum value option MAXVALUE | minvalue nocycle -- always accumulate, no loop CACHE 10; -- if efficiency is pursued, you can set the CACHE. if the service is interrupted abnormally, such as Oracle downtime or power failure, the sequence may not continue, if no cache is used, write NOCHACHE here and create the trigger: www.2cto.com SQL code CREATE OR REPLCAE TRIGGER tri_name -- TRIGGER name BEFORE INSERT ON tbl_name -- triggers FOR EACH ROW BEFORE inserting data to the tbl_name table -- indicates that the TRIGGER is a ROW-Level TRIGGER BEGIN -- the TRIGGER starts -- run the following code to SELECT seq_name.nextval: new. tbl_id FROM tbl_name -- seq_name.nextval returns the next value of the sequence. Set this value to a new value and insert it into the tbl_id column of the primary key in the tbl_name table. END -- when the trigger ends, the Oracle primary key auto-increment settings are completed.