This week's book giveaway is in the Java in General forum. We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line! See this thread for details.
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 6 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.