0

I have a MySQL table where I need to store the TIMESTAMP from when the row was created (registration TIMESTAMP). How do I create a field that is only TIMESTAMPed when it is created, and never when the row is updated?

1

3 Answers 3

1

when you create the table you put the default value of the column to be current_timestamp(). Somewhere along these lines.

create table `x` (
  id integer auto_increment not null, 
  timestamp TIMESTAMP default current_timestamp
  data CHAR(100)
);

and you don't set the field on insert/updates.

Sign up to request clarification or add additional context in comments.

Comments

0

Whenever you create a new row simply add the TIMESTAMP to it. ALternatively you make it the default

CREATE TABLE your_table(name VARCHAR32, your_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

Comments

0

On the MySQL INSERT statement, I passed a value of NOW() which records the current time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.