how to create new table in mysql with date default value for current date?
Solution 1:
You can use current_date
create table People (
first_name varchar(15) not null,
last_name varchar(15) not null,
registration_date date not null DEFAULT (CURRENT_DATE)
);
Solution 2:
This works, I tested on MySQL 8.0.27.
mysql> create table People (
first_name varchar(15) not null,
last_name varchar(15) not null,
registration_date date not null default (current_date));
Note the parentheses around the default expression. This is required.
mysql> insert into People (first_name, last_name) values ('Bill', 'Karwin');
mysql> select * from People;
+------------+-----------+-------------------+
| first_name | last_name | registration_date |
+------------+-----------+-------------------+
| Bill | Karwin | 2022-01-13 |
+------------+-----------+-------------------+
Expressions as column defaults is a new feature introduced in MySQL 8.0.13, so it won't work in older versions of MySQL. See https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html for more information.