I've got a table using the following column:
NOTEID NUMBER NOT NULL,
For those intents and reasons, this column may be the primary key. This table includes a couple of 1000 rows, each having a unique ID. Before, the applying would Choose the MAX() value in the table, add one, then use that because the next value. This can be a horrible solution, and isn't transaction or thread safe (actually, before they did not actually have a UNIQUE constraint around the column and I saw exactly the same NOTEID was copied in 9 different occasions)..
I am rather a new comer to Oracle, so Let me be aware of best syntax to change this table making this column auto-increment rather. If at all possible, Let me result in the next value within the sequence function as the MAX(NOTEID) + one in the table, or simply allow it to be 800 or something like that to begin. Thanks!
In case your MAX(noteid) is 799, then try:
CREATE SEQUENCE noteseq START WITH 800 INCREMENT BY 1
When placing a brand new record, for that NOTEID column, you'd do:
You cannot affect the table. Oracle does not support declarative auto-incrementing posts. You may create a sequence
CREATE SEQUENCE note_seq START WITH 800 INCREMENT BY 1 CACHE 100;
Then, you may create a trigger
CREATE OR REPLACE TRIGGER populate_note_id BEFORE INSERT ON note FOR EACH ROW BEGIN :new.note_id := note_seq.nextval; END;
or, if you wish to allow phone callers to specify a non-default
CREATE OR REPLACE TRIGGER populate_note_id BEFORE INSERT ON note FOR EACH ROW BEGIN IF( :new.note_id is null ) THEN :new.note_id := note_seq.nextval; END IF; END;