我正在设计一个数据库,我有如下结构:另一个数据库设计问题
是一个游戏数据库,我会有用户,游戏和组。
A game will have 1 owner (an user). In other words a game will be created by an user.
A game will have 1..n groups.
A group will have 1 owner (an user). In other words a group will be created by an user.
A group will have 1..n users.
A user will belong to a group. The user can't belong to more that ONE group.
A user will belong to a game. The user can't belong to more than ONE game.
我不知道如何知道哪个用户创建了一个游戏。我认为有两种可能:
- 从游戏表中添加一个外键到 用户表。
- 在用户表中添加一列,名为 gameOwner,如果用户 创建了游戏,则将其设置为true。
这里是我的表:
User
--------------------------------------
Id | PK
Name | User name (not null)
GroupOwner | Bool type. True if user has created a group.
GroupId | FK to group table. Can be null: user is not playing any game now.
Group
--------------------------------------
Id | PK
Name | Group name (not null)
GameId | FK to game table. Group belongs to this game.
Game
--------------------------------------
Id | PK
Name | Game name (not null).
我怎么能代表一个用户创建了一个游戏?
UPDATE
游戏总是需要一个所有者。
游戏的拥有者将永远是一样的。
游戏结束时可以删除。
Q1去:请问游戏的主人永远是一样的吗?例如随着时间的推移发生什么Q2:游戏是否需要拥有者才能存在,即游戏总是必须拥有一个拥有者? – trickwallett 2011-05-04 09:52:21
我更新了我的问题,并提供了更多详细信息(和您的答案)。 – VansFannel 2011-05-04 09:59:32