forums › forums › SQLyog › Using SQLyog › Timestamp For "created" And "edited"
- This topic is empty.
-
AuthorPosts
-
-
November 19, 2007 at 11:36 pm #10655Still LearningMember
I've read through the mysql timestamp manual (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html) a couple of times but can't seem to understand their explanation (having tried unsuccessfully in sqlyog schema designer to add auto increment and/or the ON UPDATE clauses etc).
Succinctly put, I have a TABLE with columns CREATED and EDITED and want
CREATED to have a CURRENT_TIMESTAMP default value
and
EDITED to have an ON UPDATE CURRENT_TIMESTAMP default value
what values to put where?
-
November 20, 2007 at 7:38 am #25406MaheshMemberStill Learning wrote on Nov 20 2007, 05:06 AM:I've read through the mysql timestamp manual (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html) a couple of times but can't seem to understand their explanation (having tried unsuccessfully in sqlyog schema designer to add auto increment and/or the ON UPDATE clauses etc).
Succinctly put, I have a TABLE with columns CREATED and EDITED and want
CREATED to have a CURRENT_TIMESTAMP default value
and
EDITED to have an ON UPDATE CURRENT_TIMESTAMP default value
what values to put where?
HI,
You can't make two columns having Current_timestamp and on update current_timestamp as default value.
MYsql doesn't allow this and will throw an error
Error Code : 1293
Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
try to execute the below sql statement will throw an error
CREATE TABLE t (
ts1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP);
Hope that i understood your problem
-
November 20, 2007 at 9:33 am #25407peterlaursenParticipant
it is a limitation with MySQL itself that only one TIMESTAMP column can use CURRENT_TIMESTAMP in definition.
-
November 20, 2007 at 6:12 pm #25408Still LearningMember
I assume so, in that when I set two columns to Timestamp datatype, one defaults (automatically) to CURRENT_TIMESTAMP and the other to:
0000-00-00 00:00:00
Yet, — and I know from the manual — you can set two columns to record a date/time in the same table. So, how do I set one to record the time when the row was created and one to record the time the row was (last) updated?
-
November 20, 2007 at 8:09 pm #25409peterlaursenParticipant
you cannot use CURRENT_TIMESTAMP more than once in table definition.
Try yourself:
create table `TableName1` (
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT ,
`ts1` timestamp DEFAULT CURRENT_TIMESTAMP,
`ts2` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
returns:
Error Code : 1293
Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
You will have to write current time to the second timestamp from the application using this table like
UPDATE TABLE … SET `ts2` = now(); — 'now() is a handy synonym for CURRENT_TIMESTAMP only!
.. you cannot solve this in the table definition! You may post a feature request to bugs.mysql.com, but I bet they heard it before!
-
-
AuthorPosts
- You must be logged in to reply to this topic.