CREATE TABLE payment
.payment_details
(
customer_id
INT NOT NULL AUTO_INCREMENT,
amount
INT NOT NULL,
mode
VARCHAR(50) NOT NULL,
payment_date
DATE NOT NULL DEFAULT CURRENT_DATE(),
PRIMARY KEY (customer_id
))
ENGINE = InnoDB;
Operation failed: There was an error while applying the SQL script to the database.
Executing:
CREATE TABLE payment
.payment_details
(
customer_id
INT NOT NULL AUTO_INCREMENT,
amount
INT NOT NULL,
mode
VARCHAR(50) NOT NULL,
payment_date
DATE NOT NULL DEFAULT CURRENT_DATE(),
PRIMARY KEY (customer_id
))
ENGINE = InnoDB;
ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘CURRENT_DATE(),
PRIMARY KEY (customer_id
))
ENGINE = InnoDB’ at line 5
SQL Statement:
CREATE TABLE payment
.payment_details
(
customer_id
INT NOT NULL AUTO_INCREMENT,
amount
INT NOT NULL,
mode
VARCHAR(50) NOT NULL,
payment_date
DATE NOT NULL DEFAULT CURRENT_DATE(),
PRIMARY KEY (customer_id
))
2
Answers
You can’t set the default value on
DATE
type in MySQL, as per the documentation.You can use
TIMESTAMP
instead and setCURRENT_TIMESTAMP
as a default value.The error in the mysql client:
This is related to the invalid syntax in your column definition for the
payment_date
. The correct syntax would be:This worked fine with MySQL Server version 8.0.30.
The following two are just the same as above: