Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>FROM THIS QUESTION</p> <p><a href="https://stackoverflow.com/questions/2536819/how-to-keep-history-of-record-updates-in-mysql">How to keep history of record updates in MySQL?</a></p> <p>One simple way to keep version history is to create basically an identical table (eg. with _version suffix). Both of the tables would have a version field, which for the main table you increment for every update you do. The version table would have a composite primary key on (id, version).</p> <p>Whenever you do an update on the actual table, you also INSERT a new row in the version table with duplicate data. Whenever you want to find the version history, all you need to do is something such as SELECT * FROM content_version WHERE id = CONTENT_ID ORDER BY version.</p> <p>If you use something like Doctrine ORM, it has a behavior that does this for you automatically via event listeners. You can check it out here: <a href="http://www.doctrine-project.org/documentation/manual/1_2/en/behaviors#core-behaviors:versionable" rel="nofollow noreferrer">http://www.doctrine-project.org/documentation/manual/1_2/en/behaviors#core-behaviors:versionable</a></p> <p>OR</p> <p>The easiest solution (depending on your specific needs) would probably be to add an on update/insert/delete trigger to your table, so you can perform extra logging when data is inserted/updated/deleted. That way even manual interventions on the db will be covered...</p> <p>Check <a href="http://dev.mysql.com/doc/refman/5.1/en/triggers.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.1/en/triggers.html</a> for more information.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload