Search code examples
mysqlsqlkeycreate-table

SQL error 1064 fail to create a table


Here is the exact code

CREATE TABLE students
(
    ID int(11),
    name varchar(45),
    lname varchar(45),
    birth date,
    PRIMARY KEY (ID)
);
CREATE TABLE schools
(
    ID int(11),
    name varchar(35),
    PRIMARY KEY (ID)
);
CREATE TABLE courses
(
    ID char(7),
    name varchar(45),
    credits tinyint(4),
    school int(11),
    PRIMARY KEY (ID),
    FOREIGN KEY (school) REFERENCES schools(ID)
):
CREATE TABLE enrollment
(
    ID int(11),
    edate date,
    estart date,
    course char(7),
    studentid int(11),
    PRIMARY KEY (ID),
    FOREIGN KEY (studentid) REFERENCES students(ID),
    FOREIGN KEY (course) REFERENCES courses(ID)
);

It runs through students and schools without problem, but when it gets to the courses table it stops with

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ': CREATE TABLE enrollment ( ID int(11), edate date, estart date, cours' at line 9


Solution

  • Turn the colon ':' into a semi-colon ';'