今晚我有一个学校项目要交,我和我的团队正在努力解决这个问题。我们比较了教授的代码,但我们找不到错误。我们不断得到“无效的表名”和“缺少右括号”。我们知道错误在代码的CONSTRAINT部分的某个地方。用户表成功创建,并且没有抛出错误,尽管所有其他表都抛出错误。有人能帮忙指出这个错误吗?我知道这是语法的问题。在创建表时,所需的结果不会有任何错误。
DROP TABLE "User";
DROP TABLE "UserFeed";
DROP TABLE "Post";
DROP TABLE "Story";
DROP TABLE "FactCheck";
DROP TABLE "Archive";
CREATE TABLE "User" (
UserID INT NOT NULL PRIMARY KEY ,
Username VARCHAR(30) NOT NULL,
FirstName VARCHAR(30) NOT NULL,
LastName VARCHAR(30) NOT NULL,
DateOfBirth DATE NOT NULL,
Email VARCHAR(50) NOT NULL);
CREATE TABLE UserFeed (
UserFeedID CHAR(10) NOT NULL PRIMARY KEY,
PostCount INT NOT NULL,
FollowerCount INT NOT NULL,
FollowingCount INT NOT NULL,
UserID INT NOT NULL,
CONSTRAINT FK_UserUserFeed
FOREIGN KEY (UserID)
REFERENCES User(UserID)
);
CREATE TABLE "FactCheck" (
RevisionID INT PRIMARY KEY NOT NULL,
TrueFalse VARCHAR(1) NOT NULL,
UserFeedID CHAR(10) NOT NULL,
CONSTRAINT FK_UserFeedID
FOREIGN KEY (UserFeedID)
REFERENCES UserFeed(UserFeedID)
);
CREATE TABLE "Post" (
PostID CHAR(10) PRIMARY KEY NOT NULL,
Caption VARCHAR(300) NULL,
LikeCount INT NOT NULL,
CommentCount INT NOT NULL,
DatePosted DATE NULL,
UserFeedID CHAR(10) NOT NULL,
RevisionID INT NOT NULL,
CONSTRAINT FK_UserFeedID
FOREIGN KEY (UserFeedID)
REFERENCES UserFeed(UserFeedID)
CONSTRAINT FK_RevisionID
FOREIGN KEY (RevisionID)
REFERENCES FactCheck(RevisionID));
CREATE TABLE "Story" (
StoryID CHAR(10) PRIMARY KEY NOT NULL,
StoryCaption VARCHAR(100) NULL,
Duration INT NOT NULL,
UserFeedID CHAR(10) NOT NULL,
StoryDate DATE NULL,
RevisionID INT NOT NULL,
CONSTRAINT FK_UserFeedID
FOREIGN KEY (UserFeedID)
REFERENCES UserFeed(UserFeedID)
CONSTRAINT FK_RevisionID
FOREIGN KEY (RevisionID)
REFERENCES FactCheck(RevisionID)
);
CREATE TABLE "Archive" (
ArchiveID CHAR(10) PRIMARY KEY NOT NULL,
PostID CHAR(10) NOT NULL,
StoryID CHAR(10) NOT NULL,
CONSTRAINT FK_PostID
FOREIGN KEY (PostID)
REFERENCES Post(PostID)
CONSTRAINT FK_StoryID
FOREIGN KEY (StoryID)
REFERENCES Story(StoryID)
);
1条答案
按热度按时间e0bqpujr1#
A few things:
User
is a reserved word, so you should choose a different table name (or keep it quoted, and then quote it everywhere)See below example: