Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
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. – Abadis Feb 25 '13 at 11:00
Yes, these are problems. The other solution is just to add "and not deleted" to every where clause. There is no free lunch. – Chris Travers Feb 25 '13 at 11:41
I think mysql and other db engines must do sth about this! – Abadis Feb 25 '13 at 13:41
You could probably repurpose Oracle's row-level security to do something like it.... – Chris Travers Feb 25 '13 at 14:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.