Learn How to Create PK from Sequence Trigger in SQL Developer

Learn How to Create PK from Sequence Trigger in SQL Developer

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

  1. In the connection navigator, click on the Table node to expand.
  2. Select the table for which you want to create the trigger.
  3. Right click on it and select Trigger > Create (PK from Sequence).
  4. A Create (PK from Sequence) dialogue window will appear.
  5. Specify a name in the Trigger Name field.
  6. Select a sequence from the Sequence Name drop-down list.
  7. Then select the column name from the Column Name drop-down list, for which you want to set auto increment.
  8. 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;
/

See also: