views:

24

answers:

2

Hi there,

I raised a question about this a while ago but I'm still having an issue. I have a mysql5 database with a sales table that contains a timestamp to represent a sale. If a field in the sales table in amended or altered the timestamp updates to the current time (the time of the change). To prevent this I have unselected the on_update_select_current_timestamp option but still the timestamp changes?

Here's how the field looks in phpmyadmin

alt text

Does anyone have any idea what I should do, unchecking the CURRENT_TIMESTAMP option seems to reset the on_update_select_current_timestamp trigger

A: 

if you don't want this field to be updated automatically, just do not use timestamp type field at all
Use datetime instead.

Col. Shrapnel
Bit of a dumb question here but... My database has thousands of records, if I change the database table so that the timestamp field is a datetime will it screw up my site, for example my sql inserts won't work, sales times won't be formatted correctly?
Mike Sav
@Mike yes it's bit of a dumb question. You have to change your code as well. My answer was not about your legacy code and how to deal with silly design flaws. But just about database design, how to use your tool properly. Consequences for the legacy code is another matter. Although there is nothing bad in code rewriting. It is called refactoring and it's part of your job.
Col. Shrapnel
however you're lucky because in mysql5 timestamp has the same format as datetime, afaik
Col. Shrapnel
Design flaws! You've hit the nail on the head! I've learned alot from my design flaws! Thanks for the help.
Mike Sav
A: 

Check the table definitions, if the CURRENT-TIMESTAMP option is really disabled.

If its disabled, it should look like...

CREATE TABLE `sometable` (
  ...somefields...
  `Sale_Time` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' INT(11) DEFAULT NULL,
  ...somefields...
) ENGINE=someengine

...otherwise the CURRENT-TIMESTAMP would be visible in this line. When it is disabled, it doesn't update on an update, unless some other database function (Trigger or such) changes it while updating fields.

Björn