外键疑问-mysql
请教一个简单的问题。我有三张桌子。
GROUP
id area
1 Multimedia
4 Education
就业
id foreign key(GROUP) job
1 1 designer
2 4 professor
3 1 copy
现在假设我有这个
SpecificProperties,
id foreign key (Employment) properties
1 1 type of contract
2 1 number of jobs
3 2 duration contract (no type of contract)
4 2 number of jobs
在这种情况下,设计师和教授拥有工作的属性数量。所以基本上问题是,我需要重复每个职业的工作数量吗?有什么办法可以避免吗?或者我可以有工作数量 8 个外键到 8 个不同的工作?一个给设计师,另一个给教授,另一个给文案,等等?这样第一个作业数在外键中就有了 1 || 2 || 3
像这样的:
**SpecificProperties**
id foreign key (Employment) properties
1 1 type of contract
2 1||2||3||4 number of jobs
3 2 duration contract (no type of contract)
谢谢
one simple question please. I have three tables.
GROUP
id area
1 Multimedia
4 Education
Employment
id foreign key(GROUP) job
1 1 designer
2 4 professor
3 1 copy
and now suppose that i have this
SpecificProperties
id foreign key (Employment) properties
1 1 type of contract
2 1 number of jobs
3 2 duration contract (no type of contract)
4 2 number of jobs
the designer and the professor in this case have the property number of jobs. So basically the question is, i need repeat the number of jobs for each profession? there is any way to avoid? or i can have to number of jobs 8 foreign keys to 8 different jobs for example ? one for designer, other for professor, other for copy, and so on? in this way the first number of jobs have in the foreign key 1 || 2 || 3
something like this:
**SpecificProperties**
id foreign key (Employment) properties
1 1 type of contract
2 1||2||3||4 number of jobs
3 2 duration contract (no type of contract)
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将属性名称放入附加表中,例如
然后使用
SpecificProperties
作为反映多对多关系的联结表 - 一个或多个作业可以具有一个或多个属性,因此不必为每个作业放置“作业数量”,而只需从属性表中放置其 ID。
@评论
但是,如果“作业数量”是一个字段而不仅仅是要显示的文本,那么它不应该作为行值出现在 SpecificProperties 中。相反,它应该作为列名称,但不能与合同信息一起出现。
例子:
Bob 是多媒体设计师,从某个日期一直工作到另一个日期,签订了一份价值一定金额的 x 类型合同,等等。
具有列(id,user_id,job_id,start_date,end_date,salary)的表合同(或就业)可以保存有关该信息的信息,但是因为更多的人可以做完全相同的工作以避免存储冗余数据,我们可以使用外键 job_id 来工作包含列(id、group_id、job_name、number_available)的表。所以我们知道我们总共可以有 10 名设计师从事多媒体工作,无论他们实际获得的合同是什么。
You can put names of properties in additional table, like
then use
SpecificProperties
as junction table reflecting many-many relationship - one or more jobs can have one or more properties, so instead of putting "number of jobs" for every job you just put its id from Properties table.
@comments
But if "number of jobs" is a field and not just a text to display then it shouldn't be in SpecificProperties as row value. Instead it should be somewhere as column name, but not together with contract info.
Example:
Bob is multimedia designer, working since some date until some other date, on a contract of type x worth somemoney and so on.
Table Contracts (or Employment) with columns (id,user_id,job_id,start_date,end_date,salary) can hold info about that, but because more people can work doing exactly the same to avoid storing redundant data we can use foreign key job_id to Jobs table with columns (id,group_id,job_name,number_available). So we know we can have total 10 designers working in multimedia no matter what contracts they actually got.