Search code examples
mysqldatabasemysql-error-1064create-table

Error in SQL statement


I cannot find this error in the sql, could anyone help?

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 'ID MEDIUMINT(9) NOT NULL AUTO_INCREMENT, datetimeTIMESTAMP, title TEXT NOT' at line 1

CREATE TABLE tableName1 (
    ID MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
    timestamp TIMESTAMP NOT NULL,
    title TEXT NOT NULL,
    titleEdited TEXT,
    description TEXT NOT NULL,
    descriptionEdited TEXT,
    URL VARCHAR(255) NOT NULL,
    URLEdited VARCHAR(255),
    imgPath VARCHAR(255) NOT NULL,
    PRIMARY KEY (ID),
    UNIQUE KEY (URL, imgPath)
)

CREATE TABLE tableName2 (
    ID MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
    linkID MEDIUMINT(9) NOT NULL,
    timestamp TIMESTAMP NOT NULL,
    comment TEXT NOT NULL,
    userID BIGINT(20) NOT NULL,
    PRIMARY KEY(ID),
    FOREIGN KEY(linkID) REFERENCES tableName1(ID),
    FOREIGN KEY(userID) REFERENCES users(ID)
)

Solution

  • I think the only thing that is wrong here is that mySQL needs a semicolon after each execution. You should just have to end each create table with a ; and this should work

    Here is a SQL Fiddle to prove that. (Minus the FK to users since that table is not in your example)