Reputation: 227
I tried this code
CREATE TABLE users (
userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL,
password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate DATETIME DEFAULT CURRENT_TIMESTAMP() NOT NUll,
updatedDate DATETIME
);
but the following error will come
thanks
Upvotes: 5
Views: 18454
Reputation: 319
Try this code, it should work.
CREATE TABLE users (
userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL,
password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate DATETIME DEFAULT CURRENT_TIMESTAMP NOT NUll,
updatedDate DATETIME
);
Upvotes: -1
Reputation: 3756
Use simply CURRENT_TIMESTAMP
instead CURRENT_TIMESTAMP()
CREATE TABLE users (
userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL, password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate DATETIME DEFAULT CURRENT_TIMESTAMP NOT NUll,
updatedDate DATETIME
);
In addition, you can initialize or update any TIMESTAMP column to the current date and time by assigning it a NULL value, unless it has been defined with the NULL attribute to permit NULL values.
For more knowledge click the link http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
Upvotes: 5
Reputation: 91
Change the datatype datetime
to timestamp
it will work.
CREATE TABLE users ( userId INT PRIMARY KEY AUTO_INCREMENT NOT NUll,
account VARCHAR(200) NOT NULL,
password varchar(200) NOT Null,
isActive varchar(10) NOT NUll,
createdDate **timestamp** DEFAULT CURRENT_TIMESTAMP() NOT NUll,
updatedDate DATETIME )
Upvotes: 0