I am using Oracle SQL. There is a sequence and trigger used for id that increments from 1 every time a new record is added in the table. However if all the records are deleted and new records to be added this table, the id doesn't starts from 1 whilst it starts from the last maximum number of records recorded in the sequence.
Therefore is there a way in TRIGGER statement where I can reset the sequence if the table is empty and new records get imported.
OR do I have to do stored_procedure way, if that then how can i call this using myBatis mapper?
Table (customer_info)
customer_id customer_name customer_location
1 Arbin USA
2 Tim Canada
3 Rachel Australia
Sequence
CREATE sequence customer_id_seq START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;
Trigger
CREATE OR REPLACE TRIGGER customer_id
BEFORE INSERT ON customer_info
FOR EACH ROW
BEGIN
SELECT customer_id_seq.NEXTVAL
INTO :new.customer_id
FROM dual;
END;
/
Thank you.