While creating a table I am getting the following error:
ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
The problem is that I don't actually have two columns TIMESTAMP
with CURRENT_TIMESTAMP
as default, neither I am using ON UPDATE
clause.
The DDL query I'm trying to execute is
CREATE TABLE user( /* Basic Information */ id INT NOT NULL AUTO_INCREMENT, firstname VARCHAR(255) NOT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, username VARCHAR(255) NOT NULL UNIQUE, password CHAR(40) NOT NULL, /* System status information */ active BOOL NOT NULL DEFAULT FALSE, validated BOOL NOT NULL DEFAULT FALSE, date_validated TIMESTAMP, date_registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, /* Index */ PRIMARY KEY (id) ) Engine=InnoDB;
What's causing the issue?
Use of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP is specific to TIMESTAMP. The DEFAULT clause also can be used to specify a constant (nonautomatic) default value; for example, DEFAULT 0 or DEFAULT '2000-01-01 00:00:00'.
MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'. even if they also say: Invalid DATE, DATETIME, or TIMESTAMP values are converted to the “zero” value of the appropriate type ('0000-00-00' or '0000-00-00 00:00:00').
NOW() returns a constant time that indicates the time at which the statement began to execute. NOW() returns the time at which the function or triggering statement began to execute, but SYSDATE() returns the exact time at which it executes. And CURRENT_TIMESTAMP , CURRENT_TIMESTAMP() are synonyms for NOW() .
Timestamps in MySQL are generally used to track changes to records, and are often updated every time the record is changed. If you want to store a specific value you should use a datetime field.
You can use two timestamp in one table. For default, use DEFAULT field first and then the rest timestamp fields.
Below query should work.
CREATE TABLE myTable ( id INT, date_registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, date_validated TIMESTAMP );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With