AmusableLemur
AmusableLemur

Reputation: 108

MySQL column to log when row was added

Is there an easy way to add a column to a table that stores when the row was created? Also, is it possible to do this with a column storing when it was last modified as well?

Upvotes: 0

Views: 60

Answers (3)

Fenton
Fenton

Reputation: 250972

You can create columns with a default value for when the record was created and you can create a column that updates when the record is updated:

CREATE TABLE MyTable(
    LastUpdated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

Upvotes: 2

Ahmad
Ahmad

Reputation: 12737

You can do that with a TimeStamp column by having its type as Date and a default value as current_timestamp

Upvotes: 0

RobIII
RobIII

Reputation: 8821

You can use triggers to do this.

Upvotes: 0

Related Questions