In SQL Developer, there is an option to create PK from Sequence trigger. Which creates a trigger for a table using the sequence for auto increment in Oracle table column. In this tutorial, you will learn how to create PK from Sequence trigger in SQL developer for an Oracle table.
Follow These Steps To Create A Trigger For Auto Increment Column Using SQL Developer
- In the connection navigator, click on the Table node to expand.
- Select the table for which you want to create the trigger.
- Right click on it and select Trigger > Create (PK from Sequence).
- A Create (PK from Sequence) dialogue window will appear.
- Specify a name in the Trigger Name field.
- Select a sequence from the Sequence Name drop-down list.
- Then select the column name from the Column Name drop-down list, for which you want to set auto increment.
- Click on Apply button to create the trigger.
Your trigger will be created. Below is an example of a created trigger.
CREATE OR REPLACE TRIGGER seq_trig before insert on "SCOTT"."EMP" for each row begin if inserting then if :NEW."SEQ_NO" is null then select EMP_SEQ.nextval into :NEW."SEQ_NO" from dual; end if; end if; end; /