5

I have this case :

enter image description here

UserSettings is not really a junction table since it only has one FK, which is gonna be unique, one UserSettings for one User. Should UserSettings have UserId marked as Primary Key even if UserId is a unique FK or is it unnecessary ?

4

3 回答 3

2

如果您想确保这个“这将是唯一的”要求,那么您需要将 UserID 定义为 UNIQUE 或主键约束。

于 2013-11-03T15:27:54.150 回答
2

UserSettings理想情况下不应该存在。从逻辑上讲,所有这些都是一张桌子。

如果您希望保留一个单独的表(这可能对性能或架构有用),您可能应该使用相同的主键。也就是说,UserSettings应该使用FK作为PK。这有利于性能、存储空间和简单性。

于 2013-11-03T14:35:05.243 回答
2

除了少数例外,每个表都应该有一个主键。所以是的,即使它也是外键,我也会将其设为主键。

于 2013-11-03T16:33:46.580 回答