You can add a new table to your schema called ID_Table , which will have only one numeric column called current_id with a default value of 0, when adding a new row to any other schema table that you should call, select ID_Table, returning ID_Table.current_id + 1 as the new id value. Then you need to update ID_Table
Update ID_Tableset ID_Table.current_id = ID_Table.current_id + 1
the GetNewId function can be implemented by locking ID_Table
ID_Table Update
return newid
something like this (I used Oracle syntax)
create table ID_Table( current_id number ); Insert into ID_Table values(0); CREATE OR REPLACE Function GetNewId RETURN number is new_id ID_Table.current_id%type; row_count number; begin select nvl(ID_Table.current_id, 0) + 1 INTO new_id FROM ID_Table for update; update ID_Table set ID_Table.Current_Id = new_id; commit; RETURN new_id; end GetNewId;
source share