简体   繁体   English

板球管理器的SQL查询

[英]Sql query for Cricket Manager

I have an 2 Table 我有2张桌子

TEAMS -TeamId,TeamName,Country
Players-PlayerID,PlayerName,TotalScore,ToTalMatch,TotalRuns,AvgRunRate.

Now I want to create a table TEAMPLAYERS..which has to contain TEAMID,PlayerId...and if details is deleted in TEAMS,PLAYERS table..the data must be delete in THIRD TABLE..PLS HELP ME 现在,我要创建一个表TEAMPLAYERS ..,其中必须包含TEAMID,PlayerId ...,如果在TEAMS,PLAYERS表中删除了详细信息,则该数据必须在第三表中删除。.请帮助我

Here is how you create a table with foreign key constraint with 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
.....
);

Note: ... are to be filled with other desired columns/constraints on TEAMPLAYERS table. 注意:...将在TEAMPLAYERS表上填充其他所需的列/约束。 Additionally, refer to this other post which asks a similar question MySQL foreign key constraints, cascade delete 此外,请参阅此其他帖子,它询问类似的问题MySQL外键约束,级联删除

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM