组合键= [外键+主键] [英] Composite key =[foreign key+primary key]

查看:153
本文介绍了组合键= [外键+主键]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个表=学生[s_id是pk]

1st Table = Student [s_id is pk ]

第二张表= Teacher [t_id是pk,s_id是f_k]在这里,我想创建组合键[comp_id]组合在一起(t_id [pk] + s_id [f_k])

2nd table = Teacher[t_id is pk , s_id is f_k] here i want to create composite key[comp_id] combining (t_id[pk] + s_id[f_k])

并且该复合键用作拼贴表的外键

and that composite key use as foreign key to collage table

3rd table = Collage [col_id是pk,comp_id为f_k]

3rd table= collage[col_id is pk, comp_id as f_k ]

如何使用J_PA存储库和Spring Boot m_v_c

how to do in using J_PA repository and spring boot m_v_c

推荐答案

该设计会使您的Teacher表多对多,您应将其标准化为:

That design would make your Teacher table Many-to-many, which you should normalise like so:

CREATE TABLE #Student
(
    id INT -- student
)

CREATE TABLE #Teacher
(
    id INT -- teacher
)

CREATE TABLE #TeacherStudent
(
    id INT,   -- optional
    t_id INT, -- teacher
    s_id INT  -- student
)

您可以在TeacherStudent表上创建id或从该表中的其他ID创建复合键.

You could create an id on the TeacherStudent table or create a composite key from the other id's you have in that table.

这篇关于组合键= [外键+主键]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆