mysqlsqlddl

how to create new table in mysql with date default value for current date?


I am trying the following code:

create table People (
  first_name varchar(15) not null,
  last_name varchar(15) not null,
  registration_date date not null); 

How can I make a default value for the date column? try the now(), but it is not valid..


Solution

  • 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)
    );