"Building the updating function just like inserting function" is a good or bad solution? [closed]

StackOverflow https://stackoverflow.com/questions/16521701

  •  21-04-2022
  •  | 
  •  

Question

Ok, i want to build a very complicated system that allows users to complexly manipulate data before inserting the data into Mysql DB.

So, that system must have:

  1. an inserting function (function 1) to allows user to insert data into the system.
  2. a reading function (function 2) to read the data from DB, after that users can complexly manipulate data.
  3. an updating function (function 3). After user did a lot of modifying in function 2, users will then update the data. The new data is not exactly the same as the old data (ie there may be more data than before & the data was manipulated very differently than before)

OK, now, it's quite hard to do the function 1, function 2 is not too hard, but the function 3 will be extremely hard if we actually modify the old data in DB.

So, here is my solution, instead of spending a lot of time to build function 3 (& we're not sure whether it has error-free since it's too complicated), i decided to not to build the the function 3, but just insert the new data into Db & delete the old data. It means the function 3 is exactly the function 1, the only different is we have to delete the old data that was inserted in the function 1.

So, i decided to use Auto-Increment & Int in Mysql.

But since we may update the data (maybe 300 to 500 rows) many times (probably 20 times in 4 years), it means we have to delete the old data 20 times & the Auto-Increment field keeps increasing the number.

My question is,

  • "Do not build the updating function & building the updating function just like inserting function" is a good or bad solution?

  • Second, "if we build the updating function just like inserting function, then will it be a stable system?"

  • Third, "if we build the updating function just like inserting function, then will, 1 day, we run out of the number (max int is 2147483647)?"

In my opinion, i prefers the solution "building the updating function just like inserting function" since we can keep the old data as the previous version, we don't even need to delete it & it saves me a lot of times. Also, 2147483647 is too big & life is short, do you think so?

Note:

  1. The data was stored on the main table, it means this table has no foreign key, other tables have to use data in this table as foreign key?
  2. We can keep the old data as the previous version. After the new data was inserted, & if user search for info, the system will look into the new data, not old data. Of course, he can have option to look at the old data by clicking see previous version.
Was it helpful?

Solution

First, i have to say this is a very bad design, don't do it! you can encounter a serious syncronization errors , for example, what if you are updating(removing the old one and inserting the new) and someone want to read the data? he can get an error, in other words, this is very unstable .

use a simple update function with the increment value as id, prepare your update statement like update mytable set v1=?, v2=?, ...., vn=? where id=? and populate all the data again.

second, yes, int is just 2^31, but you can specify a bigger Integer, but again, this is a bad solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top