给定设计:
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’)
);
创建匹配表,假设匹配ID,玩家ID和teamID列的数据类型为VARCHAR2(5)
。匹配的结果是指homeTeam,只能是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’)
);
答案 0 :(得分: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)但我建议它们要么被更改,要么你发现那些表是真正的主键,它是一个整数或者有一个添加。这是正确的做法(虽然意见会有所不同)。