[英]primary key as foreign key
i have this design我有这个设计
table: users
-------------
PK id_users
users
table: single_users
--------------------
PK FK users_id_users
something
table: workers
---------------
PK FK single_users_users_id_users
something
there is any problem to make a PK as foreign key?将PK作为外键有什么问题吗? like the example above?
像上面的例子?
thanks谢谢
I think that's just fine as long as you have the one to many relationship between users to workers, and users to single_users.我认为这很好,只要您在用户与工人之间以及用户与 single_users 之间具有一对多的关系。
Note: you will have to have a multiple valued PK though.注意:虽然你必须有一个多值的PK。 Eg
例如
users
1 Al
2 Eve
3 Bob
user_workers
1 something_1
1 something_2
So, you would have to have the id and something as a composite primary key.因此,您必须将 id 和某些内容作为复合主键。 Its often easier to give the workers an id field that is a primary key.
为工人提供一个作为主键的 id 字段通常更容易。
So:所以:
user_workers
id | user_id | something
1 1 something_1
2 1 something_2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.