我有一张2桌
TEAMS -TeamId,TeamName,Country
Players-PlayerID,PlayerName,TotalScore,ToTalMatch,TotalRuns,AvgRunRate.
现在我要创建一个TEAMPLAYERS ...表,它必须包含TEAMID,PlayerId ...如果在TEAMS,PLAYERS表中删除了详细信息,那么数据必须在THIRD TABLE ... PLS HELP ME中删除
答案 0 :(得分:0)
以下是使用cascade delete创建具有外键约束的表的方法。
CREATE TABLE TEAMPLAYERS (
.....
teamId int(11) NOT NULL,
playerId int(11) NOT NULL,
FOREIGN KEY(teamId)
REFERENCES TEAMS(teamId)
ON DELETE CASCADE,
FOREIGN KEY(playerId)
REFERENCES PLAYERS(playerId)
ON DELETE CASCADE
.....
);
注意:......将在TEAMPLAYERS表上填充其他所需的列/约束。 另外,请参阅另一篇文章,其中提出了类似的问题MySQL foreign key constraints, cascade delete
希望这有帮助!