Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

sql server - Composite key =[foreign key+primary key]

1st Table = Student [s_id is pk ]

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 is pk, comp_id as f_k ]

how to do in using J_PA repository and spring boot m_v_c

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...