-3

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

  • Possible duplicate of [Foreign Key to non-primary key](https://stackoverflow.com/questions/18435065/foreign-key-to-non-primary-key) – Mathieu VIALES Oct 26 '17 at 07:28
  • 1
    Welcome to SO. This site is not a code-writing service and is not meant for delivering complete solutions. Users are expected to show some effort and code whilst SO is here to help you solve specific programming problems along the way. Have you tried anything already? Please read: https://stackoverflow.com/help/asking – Maciej Jureczko Oct 26 '17 at 07:38
  • i want to create composite key[ck] =[pk+fk]......................... – Sandip Mulmule Oct 26 '17 at 07:38

1 Answers1

2

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.

Tanner
  • 22,205
  • 9
  • 65
  • 83