简体   繁体   English

仅当值在另一个表中时才使用Oracle INSERT

[英]Oracle INSERT only if values are in another table

I have two tables: 我有两个表:

players (has a team name column) and teams (also has a team name column) 玩家(具有“团队名称”列)和团队(也具有“团队名称”列)

I want to only allow inserts of new players if the team name exists in the team table. 如果球队表中存在球队名称,我只允许插入新球员。

Any help would be appreciated. 任何帮助,将不胜感激。 Please keep it simple because I'm still learning. 请保持简单,因为我还在学习。

Then supposedly you should make the TeamName column in the Teams table a Primary Key and the TeamName column in the Players table a Foreign Key, pointing to the one in the TeamName column of the Teams table. 然后,假设您应该将Teams表中的TeamName列作为主键,而Players表中的TeamName列作为外键,指向Teams表的TeamName列中的一个。

Notice though that using "TeamName" as the indentifier of the team is not such a good idea - it would be a better idea to have a Team_ID columns which is just some arbitrary number, so that if the team name changes, you won't have to change it in all the rows in the Players field that point to it. 请注意,尽管使用“ TeamName”作为团队的标识不是一个好主意-最好有一个Team_ID列,它只是一些任意数字,因此,如果团队名更改,您将不会必须在“玩家”字段中指向它的所有行中进行更改。

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

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