0

I already have table, how to add new auto increment column. by using sequence or trigger?

2 Answers2

0

You could use annotation in the Entity like:

@SequenceGenerator(name = "PK", sequenceName = "SQN_TABLENAME", allocationSize = 1)

or add a trigger:

How to create id with AUTO_INCREMENT on Oracle?

Community
  • 1
  • 1
Ardi Goxhaj
  • 362
  • 2
  • 15
0

If you have existing table and wants to add new column then add new column using ALTER Query

ALTER TABLE table_name ADD (id varchar2(45));

then create one sequence for auto increment values

*

CREATE SEQUENCE seq_name
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20;

*

create trigger to add values after new record is inserted into table

create or replace trigger trg_name before insert on table_name for each row begin select seq_name.nextval into :new.idfrom dual; end;

now you will able to add new id auto. into table :)

Note: do not set NOTNULL true for this column, else you will face problem while returning result set in java

hope this will help you :)