OneBite.Dev - Coding blog in a bite size

Why do we need to save created_at and update_at field in database

What is created_at and update_at field in database? why do we need to add this fields in our database?

You might have seen created__at and updated__at field with time value in your database, without knowing what are they exists for.

Why do we need these both fields? i’m not sure about the history, but from my experience, it would be much easier when we want to play with data when both these fields exist. For example if you have a user table, you can see how active your user is by last time the _updated__at column changes.

It’s also useful to see which of your features often used by user when you have the exact time, when the action happened.

The basic idea is always save in created__at_ column when something is newly created, and everytime something happened to this data, update the updated__at column. For example in a User’s Table, created__at to see when user is register, and _updated__at when the user log in or edit their profile.