0

I have a users table that has a column for the date that they joined. It is a timestamp datatype. I want the value of the column to always be the current time when the user joined, so the default value is the current time. If the user's profile is updated, the user's join date is updated to the current time. In other words, say a user joins on August 2nd and then updates their profile on September 17th. The new value of the join date will be September 17th. This happens even though I don't tell my sql statements to update that row.

How can I make it so that the timestamp column is only affected when a new row is created?

ShoeLace1291
  • 4,551
  • 12
  • 45
  • 81

1 Answers1

0

Sounds like you need to configure the default constraint so that it populates the column on insertion only:

DEFAULT CURRENT_TIMESTAMP
ALTER TABLE table CHANGE datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

Changing it to only be this means that any revisions will not trigger the timestamp value to be updated.

J.Rob
  • 436
  • 1
  • 5
  • 22