I have always been a fan of using a single table instead of breaking it down into an “active” table and a “history” table. I put 4 columns on these tables, all the timestamps: created, deleted, started, completed. "created" and "deleted" are pretty straightforward. The timestamps "start" and "end" mean that the record was actually an "active" record. The current active record will have a "start" time until now() and NULL "end". By separating the “created” and the “starting” times, you can plan for changes that will take place in the future.
This design, unlike the two-story design, allows you to easily write queries that will automatically work with the necessary data. Suppose your table stores the tax rate over time ... you don’t want all your queries using tax rates in their calculations to have additional difficulty in deciding how to look in the history table when processing old invoices , for example ... you can simply find the tax rate that is valid at the time of the invoice in one request, regardless of whether the current tax rate or not.
This idea was originally not mine (although I myself reinvented the original idea before reading about it) ... you can find a detailed discussion of this in this online book .
source share