Skip to content
Advertisement

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..

Advertisement

Answer

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)
); 
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement