I already have table, how to add new auto increment column. by using sequence or trigger?
2 Answers
You could use annotation in the Entity like:
@SequenceGenerator(name = "PK", sequenceName = "SQN_TABLENAME", allocationSize = 1)
or add a trigger:

- 1
- 1

- 362
- 2
- 15
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 :)

- 325
- 1
- 2
- 11