mysql

Create table with date column


I want to create a student table with column 'student_birthday' and its format should be dd-mm-yy.

create table `student`.`studentinfo`(
    `student_id` int(10) not null auto_increment,
    `student_name` varchar(45) not null,
    `student_surname` varchar(45) not null,
    `student_birthday` date(???),
    (some lines of code)
primary key(student_id));

what should be inputted in the (???) to get the right format above?


Solution

  • Just use "DATE" without the brackets. The brackets are only needed for certain column types where you want to specify the maximum number of bytes/characters that can be stored.

    For MySQL, it's documented at https://dev.mysql.com/doc/refman/5.7/en/date-and-time-types.html