开发者

One to One Relationship / Unique Key Pairs

I have a database with two tables, games and regions. My goal is to keep track of the release dates in each region for the games.

Granted, regions wont change very often, but would it be bette开发者_开发问答r to create a new column for each region in games, or create a release_dates table between them?

If I create a new table between them, how would I ensure that there is only one release date for each region/game pair?


I would go with the release_dates table. This keeps you from needing NULL values in your games table if, say, a particular region isn't getting a release.

In your release_dates table, you can make region_id a foreign key and game_id a foreign key, and then make (game_id, region_id) the primary key for the release_dates table. This will ensure each (game_id, region_id) combo appears only once.


It's a many-to-many relationship. An intermediate junction table containing game_id and region_id is the right solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜