-3

给定一个设计:

Player
===========
PlayerID
TeamID
FirstName
LastName
DateOfBirth

Team
===========
TeamID
TeamName
Grade

Match
===========
MatchID
HomeTeamID
AwayTeamID
Date
Result

我正在使用这个:

 CREATE TABLE Match(
   MatchID VARCHAR2(5) NOT NULL,
   Dateofmatch date,
   Result VARCHAR2(1) ,
   HomeTeam VARCHAR2(5),
   AwayTeam VARCHAR2(5),
   CONSTRAINT MatchPK PRIMARY KEY(MatchID),
   CONSTRAINT HomeFK FOREIGN KEY(HomeTeamIDFK) REFERENCES TEAM(TeamID),
   CONSTRAINT AwayFK FOREIGN KEY(AwayTeamIDFK) REFERENCES TEAM(TeamID),
   CONSTRAINT Result
   Check (Result in (‘W’,’L’,’D’)
   );

假设 Match ID、Player ID 和 teamID 列是 data type 来创建 Match 表VARCHAR2(5)。比赛结果以主队为准,只能是 W、L 或 D。

这个对吗?


我已经出来了,请纠正我

CREATE TABLE Match (
    MatchID VARCHAR2(5) NOT NULL,
    Dateofmatch date,
    Result VARCHAR2(1) ,
    HomeTeam VARCHAR2(5),
    AwayTeam VARCHAR2(5),
    CONSTRAINT MatchPK PRIMARY KEY(MatchID),
    CONSTRAINT HomeFK FOREIGN KEY(HomeTeamIDFK) REFERENCES TEAM(TeamID),
    CONSTRAINT AwayFK FOREIGN KEY(AwayTeamIDFK) REFERENCES TEAM(TeamID),
    CONSTRAINT Result Check (Result in (‘W’,’L’,’D’)
);
4

1 回答 1

1

我的目标更像是:

CREATE TABLE match
   ( match_id INTEGER, 
     date_of_match  DATE, 
     result_type  char(1), 
     home_team_id INTEGER, 
     away_team_id INTEGER,
     CONSTRAINT match_pk PRIMARY KEY(match_id),
     CONSTRAINT home_fk FOREIGN KEY(home_team_id_fk) REFERENCES TEAM(team_id),
     CONSTRAINT away_fk FOREIGN KEY(away_team_id_fk) REFERENCES TEAM(team_id)
     CONSTRAINT result_type CHECK (result_type in (‘W’,’L’,’D’)
  )

我知道 fk 的数据类型应该是 varchar2(5) 但我建议它们要么被更改,要么你发现那些表是真正的主键,它可以是一个整数或添加一个。这是正确的做法(尽管意见会有所不同)。

于 2012-09-29T12:53:02.993 回答