Search code examples
sqlmysqlmysql-error-1064

SQL Syntax Error whilst creating a table


I have recently started learning SQL, I can't determine what is causing my syntax error (see below):

CREATE TABLE Users(
    user_id smallint not null auto_increment,
    username varchar(50) unique,
    password varchar(41),
    dob date,
    session_id varchar not null,
    cookie varchar not null,
    PRIMARY KEY(user_id),
    CONSTRAINT dob_valid CHECK(dob < current_date())
);

This does work when all varchar fields have a predefined length. Do all fields of type varchar require a size parameter?

I am sorry if this problem seems very simple.

Thanks for your help in advance


Solution

  • yes all varchar require a max size.