Updating entry WITHOUT updating timestamp
To quickly update a column without touching the timestamp, explicitly set the timestamp column to its present value. See the example below:
This approach helps maintain timestamp integrity during the update operation.
Updating without ticking the timestamp
Need to modify your table but not the timestamp values? Look no further. Here's what you need to do.
Defining default constraints
If your timestamp column is updated automatically on MySQL, simply set a default constraint for the timestamp without the ON UPDATE
trigger.
Sneaky update without mentioning timestamp
The easiest way to retain timestamp value is to exclude it while performing the update.
Updating with timestamp in the loop
In cases where you explicitly mention the timestamp in the query, set it to its existing value like this:
Special cases: Timestamp taming techniques
When it comes to managing timestamp during updates, standard methods might not always suffice. Here's how to handle those special cases:
Working with trigger-happy updates
If your table employs triggers to update timestamps, you'll need to deactivate them temporarily. Sorry, trigger – it's not you, it's us.
Bypassing ORM auto-updates
Using ORM (Object-Relational Mapping) frameworks could also auto-update timestamps. Luckily, we can outsmart them:
Preserving audit history
In cases where maintaining timestamp accuracy is paramount, consider creating a separate table for auditing. Honestly, it's like having a secret diary!
With this, each update action is recorded æ la CSI crime scene, without altering the main table's timestamp:
Was this article helpful?