Explanation: There are 2 tasks A & B which are scheduled daily & monthly respectively.
Nature of Tasks:
- All the tasks have a seq_number assigned to it which is unique.
- This Number is assigned by using MAX(seq_number)+1 from the table where the tasks are stored.
- Once the task has completed & the day has changed to schedule the next task, the older task will be deleted and a new 1 will be added.
- Until the next schedule the old task records are retained.
- seq_number is primary key for the table where these records are stored.
eg. Task A is scheduled for 30-Jun-2016 with seq_number 1, Task B is scheduled for Jun-2016 with seq_number 2. Once Task A for 30-Jun-2016 is finished its deleted and a new task will be added for 01-Jul-2016 with seq_number 3. Until the end of July the task A will keep deleting seq_number 3 record and added another task A for next day with seq_number 3. Once we reach the end of July, task B will be deleted and added with seq_number 4. Now when the task A is scheduled for 01-Aug-2016 it will take the seq_number 5.
As you can see the seq_number keeps on increasing and one day it will cap out.
My Solution:
Instead of taking max +1 we can randomly get any number in the range and assign. If we get Primary Key Unique Constraint Error then we can again randomly find another number in a loop until we find a free one.
Please advise feasible ways to fix this issue. All ideas are welcome.
edit: seq_number column is NUMBER(6) and it cannot be changed easily. The solution should be able to reuse the seq_numbers.