2
I have the database tables to store the data, but I want to add one to save the data of deleted rows from the other tables, I thought of four ways to do this:
Create a table
lixeira
that will save the table name and the primary key of the deleted line (plus other information like date, user who deleted, etc), in the other tables would add a fielddeletado
boolean type, so instead of deleting the line only changes this value (besides registering a row in the tablelixeira
)Create a table
lixeira
that will only save the information as date, user who deleted, etc, in the other tables would add a fielddeletado
which would be a foreign key to the tablelixeira
, so instead of deleting the row only changes this value (in addition to registering a row in the tablelixeira
)Create a table
lixeira
which will save the information as date, user who deleted, etc and the deleted row data formatted as JSON, excluding the row from the original tableCreate a recycle bin table for each bank table, for example,
usuario_lixeira
,produto_lixeira
, etc, and, before deleting the data in the original table, add them in your recycle bin table
In general, what would be the best alternative? What problems will I have with using method A or B? If you need to eventually search for an deleted row, can any method make this very complicated? Keeping data deleted in the original table (method 1 and 2) will reduce query performance * ? Indexing can solve this last problem?
* Considering a table that has many records and that are excluded with relative frequency
Other ways to achieve the same goal are welcome,
Did the answer resolve what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?
– Maniero