1

I have three tables in SQL Server and the relationships between them is many to many, but I don't know which one is right to make the relationships.

Is it put table for make the relationship between the book and Teacher (teacher can take more than one subject)

or

put all student and teacher and book in one relationship table for many to many

tblBook

 (PK) BookId
 BookName

tblTeacher

(pk)TeacherId
TeacherName 

tblStudent

(pk)StudentId
StudentName
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Anas
  • 35
  • 7
  • When you have a many to many relationship you need a further table that links those; a composite key table or junction table is a couple of names this goes by. This table will likely only have 2 columns, made up of 2 Foreign Keys (which together make up a Primary Key). There is plenty of information and examples on this; such as the linked duplicate. – Thom A Aug 24 '19 at 11:16
  • 1
    yes sir I know that but which one is better to but for every two table one relation table or but all three tables in one relation table – Anas Aug 24 '19 at 11:40

1 Answers1

0

You can create a table i think for storing relations. Where you can use all 3 IDs as foreign Key's.

Relation Table.

RELPKID    TeacherFKID   BookFKID  StudentFKID

1           1            2   

I hope this helps thank you

amaldec23
  • 245
  • 2
  • 11