开发者

Oracle INSERT only if values are in another table

I have two tables:

开发者_JAVA技巧

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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜