1

我在sql中找不到这个错误,有人可以帮忙吗?

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'ID MEDIUMINT(9) NOT NULL AUTO_INCREMENT, datetimeTIMESTAMP, title TEXT NOT' 附近使用正确的语法

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)
)
4

2 回答 2

2

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)

于 2012-04-25T16:12:07.963 回答
0

Are you sure you are creating this tables and getting error? I created them succesfuly.

And with looking error, it seems you are trying to create another field named datetime which type is timestamp? datetime is reserverd word. You need to use backticks.

'ID MEDIUMINT(9) NOT NULL AUTO_INCREMENT, datetimeTIMESTAMP, title TEXT NOT' at line 1

于 2012-04-25T16:12:27.937 回答