-4

我从 MySQL 收到一个错误,这是我见过的最无用的错误消息:

ERROR 1064 (42000): 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 'NOT NULL,
PRIMARY KEY (userID, tweetID),
FOREIGN KEY (userID) REFERENCES User(' at line 4

太好了,检查手册...> _ _>

这是 SQL 源代码;我相信任何熟悉 SQL 的人都会非常简单,但我是新手。对我来说,一切看起来都很好。

我真的很想有一个比“我的错误是什么”更完善的问题,但是错误信息如此模糊,而且我的经验如此之少,我几乎迷失了方向。

CREATE TABLE User (
    username        VARCHAR(20)     NOT NULL,
    userID          INTEGER         NOT NULL,
    fullName        VARCHAR(100),
    passwordHash    VARCHAR(256)    NOT NULL,
    email           VARCHAR(256)    NOT NULL,
    imageURL        VARCHAR(200),
    facebookURL     VARCHAR(200),
    tagline         VARCHAR(140),
    memberSince     TIMESTAMP       NOT NULL,
    PRIMARY KEY (userID)
);

CREATE TABLE Tweet (
    tweetID INTEGER                 NOT NULL,
    userID INTEGER                  NOT NULL,
    content VARCHAR(140)            NOT NULL,
    TIMESTAMP                       NOT NULL,
    PRIMARY KEY (tweetID),
    FOREIGN KEY (userID) REFERENCES User(userID)
);

CREATE TABLE HashTag (
    tweetID INTEGER                 NOT NULL,
    content VARCHAR(140)            NOT NULL,
    PRIMARY KEY (content),
    FOREIGN KEY (tweetID) REFERENCES Tweet(tweetID)
);

CREATE TABLE Follows (
    follower INTEGER                NOT NULL,
    followee INTEGER                NOT NULL,
    PRIMARY KEY (follower, followee),
    FOREIGN KEY (follower) REFERENCES User(userID),
    FOREIGN KEY (followee) REFERENCES User(userID)
);

CREATE TABLE Retweets (
    tweetID INTEGER                 NOT NULL,
    userID INTEGER                  NOT NULL,
    TIMESTAMP                       NOT NULL,
    PRIMARY KEY (userID, tweetID),
    FOREIGN KEY (userID) REFERENCES User(userID),
    FOREIGN KEY (tweetID) REFERENCES Tweet(tweetID)
);

CREATE TABLE Mentions (
    tweetID INTEGER                 NOT NULL,
    userID INTEGER                  NOT NULL,
    PRIMARY KEY (tweetID, userID),
    FOREIGN KEY (tweetID) REFERENCES Tweet(tweetID),
    FOREIGN KEY (userID) REFERENCES User(userID)
);

CREATE TABLE Favorites (
    tweetID INTEGER                 NOT NULL,
    userID INTEGER                  NOT NULL,
    PRIMARY KEY (tweetID, userID),
    FOREIGN KEY (tweetID) REFERENCES Tweet(tweetID),
    FOREIGN KEY (userID) REFERENCES User(userID)
);

CREATE TABLE CanSee (
    tweetID INTEGER                 NOT NULL,
    userID INTEGER                  NOT NULL,
    PRIMARY KEY (tweetID, userID),
    FOREIGN KEY (tweetID) REFERENCES Tweet(tweetID),
    FOREIGN KEY (userID) REFERENCES User(userID)
);

CREATE TABLE Message (
    messageID INTEGER               NOT NULL,
    senderID INTEGER                NOT NULL,
    receiverID INTEGER              NOT NULL,
    content VARCHAR(140)            NOT NULL,
    TIMESTAMP                       NOT NULL,
    PRIMARY KEY (messageID),
    FOREIGN KEY (senderID) REFERENCES User(userID),
    FOREIGN KEY (receiverID) REFERENCES User(userID)
);
4

1 回答 1

3

当它说“NEAR __ ”时,它表示在该点之前的某件事触发了错误。

在这种情况下,就是这个词TIMESTAMP。您列出了TIMESTAMP该列的类型,但从未给它命名。也许应该是这样modified_on TIMESTAMP(或类似的东西)。

于 2013-05-02T16:18:50.873 回答