patternsqlMinor
Is there a reason/benefit I am not aware of for this kind setup?
Viewed 0 times
thisbenefitreasonkindsetupfortherenotaware
Problem
I now manage a MySQL database that was designed and created by another.
I am confused about a certain setup that the original developer created..
He did not use auto increments for table IDs. Instead, he created a table called
system_sequences which has two columns:
Here is an example of a table and how it currently inserts into the table (try my best):
there is a table called customer with an unique ID column.
If I want to insert into customer, currently I have to do the following:
save the next_value into a variable and use it as the next ID for customer
then I have to:
I did not design this, I do not like it in any way shape or form ( I actually hate it ) and I want to convert everything carefully to auto_increment
But is there a reason for this or a benefit that I am not aware of? I have never seen anything like it before. And there is no documentation for this database that explains anything.
I am confused about a certain setup that the original developer created..
He did not use auto increments for table IDs. Instead, he created a table called
system_sequences which has two columns:
system_sequences.Table_Name
system_sequences.Next_ValueHere is an example of a table and how it currently inserts into the table (try my best):
there is a table called customer with an unique ID column.
If I want to insert into customer, currently I have to do the following:
SELECT system_sequences.Next_Value
FROM system_sequences
WHERE system_sequences.Table_Name = 'customer'save the next_value into a variable and use it as the next ID for customer
then I have to:
UPDATE system_sequences
SET Next_Value = Next_Value + 1
WHERE system_sequences.Table_Name = 'customer'I did not design this, I do not like it in any way shape or form ( I actually hate it ) and I want to convert everything carefully to auto_increment
But is there a reason for this or a benefit that I am not aware of? I have never seen anything like it before. And there is no documentation for this database that explains anything.
Solution
I don't know about mysql but in SQL server, you would use this type of thing when you can't afford to have gaps in the sequence from rollbacks. Often this is a requirement for invoice numbering for accounting auditing.
Context
StackExchange Database Administrators Q#15170, answer score: 4
Revisions (0)
No revisions yet.