Please let me klnow which method is more efficient in terms of performance to generate an auto increment number in oracle.
CREATE TABLE test (id NUMBER PRIMARY KEY,
CREATE SEQUENCE test_sequence
START WITH 1
INCREMENT BY 1;
Follow Step1 and Step2 and create a Trigger as below :
CREATE OR REPLACE TRIGGER test_trigger
REFERENCING NEW AS NEW
FOR EACH ROW
SELECT test_sequence.nextval INTO :NEW.ID FROM dual;
Follow Step1 and Step2 and directly have an insert statement as below:
INSERT INTO test (id, name) VALUES (test_sequence.nextval , 'Jon343');
posted 5 years ago
I'm not sure which one has the best performance, but Method 1 seems superior to me in terms of maintainability. It removes the responsibility of maintaining database integrity from the application developer, so reducing the impact of application errors on the database.