views:

61

answers:

1

Hi, 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.

+8  A: 

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.

Omer Raviv
Thanks Omer. I'm really just practicing for now and I do understand about the team_id. Thanks!
relyt