0

我正在通过 SQLFiddle 创建这些数据库表,并且出现了一个我认为没有问题的错误。它与Club底部的主键有关,告诉我(放错了位置。这个脚本有什么问题,为什么?

SQLFiddle

CREATE TABLE Club
(
  CLUB_ID int NOT NULL,
  CLUB_NAME varchar(255) NOT NULL,
  STREET_ADDRESS varchar(255) NOT NULL,
  CITY varchar(255) NOT NULL,
  STATE varchar(2) NOT NULL,
  ZIPCODE int NOT NULL,
  PHONE int NOT NULL,
  PRIMARY KEY(CLUB_ID)
);

CREATE TABLE Member
(
  MEMBER_ID int NOT NULL,
  FIRST_NAME varchar(255) NOT NULL,
  LAST_NAME varchar(255) NOT NULL,
  STREET_ADDRESS varchar(255) NOT NULL,
  CITY varchar(255) NOT NULL,
  STATE varchar(2) NOT NULL,
  ZIPCODE int NOT NULL,
  PRIMARY KEY(MEMBER_ID)
);

CREATE TABLE Phone
(
  PHONE_ID int NOT NULL,
  MEMBER_ID int,
  PHONE_TYPE varchar(255) NOT NULL,
  PHONE_NUMBER int NOT NULL,
  PRIMARY KEY(PHONE_ID),
  FOREIGN KEY(MEMBER_ID) REFERENCES Member(MEMBER_ID)
);

CREATE TABLE Membership
(
  MEMBERSHIP_ID int NOT NULL,
  MEMBER_ID int,
  CLUB_ID int,
  JOIN_DATE varchar(255) NOT NULL,
  END_DATE varchar(255),
  REASON varchar(255),
  PRIMARY KEY(MEMBERSHIP_ID),
  FOREIGN KEY(MEMBER_ID) REFERENCES Member(MEMBER_ID),
  FOREIGN KEY(CLUB_ID) REFERENCES Club(CLUB_ID)
);

CREATE TABLE Talent
(
  TALENT_ID int NOT NULL,
  TALENT_NAME varchar(255) NOT NULL,
  DESCRIPTION varchar(255) NOT NULL,
  PRIMARY KEY(TALENT_ID)
);

CREATE TABLE Member_Talent
(
  MEMBER_ID int,
  TALENT_ID int,
  PRIMARY KEY(MEMBER_ID, TALENT_ID),
  FOREIGN KEY(MEMBER_ID) REFERENCES Member(MEMBER_ID),
  FOREIGN KEY(TALENT_ID) REFERENCES Talent(TALENT_ID)
);

CREATE TABLE Award
(
  AWARD_ID int NOT NULL,
  AWARD_NAME varchar(255) NOT NULL,
  DESCRIPTION varchar(255) NOT NULL,
  PRIMARY KEY(AWARD_ID)
);

CREATE TABLE Member_Award
(
  MEMBER_AWARD_ID int NOT NULL,
  MEMBER_ID int,
  AWARD_ID int,
  AWARD_DATE varchar(255) NOT NULL,
  PRIMARY KEY(MEMBER_AWARD_ID),
  FOREIGN KEY(MEMBER_ID) REFERENCES Member(MEMBER_ID),
  FOREIGN KEY(AWARD_ID) REFERENCES Award(AWARD_ID),
);

CREATE TABLE Office
(
  OFFICE_ID int NOT NULL,
  CLUB_ID int,
  OFFICE_NAME varchar(255) NOT NULL,
  DESCRIPTION varchar(255) NOT NULL,
  PRIMARY KEY(OFFICE_ID),
  FOREIGN KEY(CLUB_ID) REFERENCES Club(CLUB_ID)
);

CREATE TABLE Officer
(
  OFFICER_ID int NOT NULL,
  OFFICE_ID int,
  MEMBER_ID int,
  YEAR int NOT NULL,
  PRIMARY KEY(OFFICER_ID),
  FOREIGN KEY(OFFICE_ID) REFERENCES Office(OFFICE_ID),
  FOREIGN KEY(MEMBER_ID) REFERENCES Member(MEMBER_ID)
);

CREATE TABLE Project
(
  PROJECT_ID int NOT NULL,
  CLUB_ID int,
  PROJECT_NAME varchar(255) NOT NULL,
  DESCRIPTION varchar(255) NOT NULL,
  PROJECT_DATE varchar(255) NOT NULL,
  PROJECT_TYPE varchar(255) NOT NULL,
  COST int NOT NULL,
  REVENUE int NOT NULL,
  PRIMARY KEY(PROJECT_ID),
  FOREIGN KEY(CLUB_ID) REFERENCES Club(CLUB_ID)
);

CREATE TABLE Member_Project
(
  MEMBER_ID int,
  PROJECT_ID int,
  PRIMARY KEY(MEMBER_ID, PROJECT_ID),
  FOREIGN KEY(MEMBER_ID) REFERENCES Member(MEMBER_ID),
  FOREIGN KEY(PROJECT_ID) REFERENCES Project(PROJECT_ID)
);
4

1 回答 1

1

找到给你问题的指令......

CREATE TABLE Member_Award
(
  MEMBER_AWARD_ID int NOT NULL,
  MEMBER_ID int,
  AWARD_ID int,
  AWARD_DATE varchar(255) NOT NULL,
  PRIMARY KEY(MEMBER_AWARD_ID),
  FOREIGN KEY(MEMBER_ID) REFERENCES Member(MEMBER_ID),
  FOREIGN KEY(AWARD_ID) REFERENCES Award(AWARD_ID),
);

删除 , 之后Award(AWARD_ID)

SQL小提琴

于 2013-02-27T22:00:27.553 回答