Is there any way to omit some records in mysql select statement and not deleting them? We can easily add a column for example deleted and set it to 1 for deleted ones and keep them but the problem is that we have to put where deleted = 1
in all queries. What is the best way to keep some records as an archive?
Add a comment
|
1 Answer
You basically have two choices. You could use a view to do the filtering though this has some performance issues on MySQL, or you could use a trigger to copy deleted rows into an archive table. I suspect that on MySQL, the trigger solution will be much better (on other DB's the tradeoffs may go other ways.
-
Chris Travers: In View mode we will have 2 problems : first we have to make a view for each table and second is Inserts with duplicate key while you can not insert in to a view! and For Triggers , all your foreign keys will fail and again you have to make duplicate table for each table.– AbadisCommented Feb 25, 2013 at 11:00
-
1Yes, these are problems. The other solution is just to add "and not deleted" to every where clause. There is no free lunch. Commented Feb 25, 2013 at 11:41
-
-
1You could probably repurpose Oracle's row-level security to do something like it.... Commented Feb 25, 2013 at 14:18