The forum will experience an outage sometime between February 10 at 7:00pm EST and February 12 at 11:59 EST for installation of security updates. The actual time and duration of the outage are unknown but attempts will be made to minimize the downtime. We apologize for any inconvenience.

Is there a way of stopping DEFAULT TIMESTAMP columns from updating the timestamp when you perform an UPDATE statement?

We need to run an update statement on a table to fix up some data, however we don't want that update to be reflected by the UpdatedAt default timestamp column.

asked 07 Mar '12, 17:53

Nick%20Brooks's gravatar image

Nick Brooks
accept rate: 50%

You can just include the column with a value in your update statement:

Update table set UpdatedAt ='2012-01-01'

Will change the value to the 1st January...

you can even do something like this:

Update table set UpdatedAt = UpdatedAt, ...

This will leave the value as before

permanent link

answered 08 Mar '12, 02:59

Martin's gravatar image

accept rate: 14%

edited 08 Mar '12, 03:01

Just to add: The method Martin has shown does work that way since a DEFAULT TIMESTAMP is a default (though a particular one), and you can always overwrite a column default value simply by specifying a value for the column...

We use the "set UpdatedAt = UpdatedAt" form regularly to prevent such meaningful timestamps from getting updated when doing "maintenance tasks".

(08 Mar '12, 03:45) Volker Barth
Replies hidden

Don't tell the auditors... :)

(08 Mar '12, 08:30) Breck Carter

Well, the TRANSLOG will tell:)

(08 Mar '12, 08:51) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 07 Mar '12, 17:53

question was seen: 1,164 times

last updated: 08 Mar '12, 08:51