Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 many to many relationship

Author  Topic 

AJ217
Starting Member

3 Posts

Posted - 2014-05-05 : 13:25:27
Hi, why do we need a junction table in a many to many relationship? Why can't everything be in just 2 tables?

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-05-05 : 13:40:14
How would you model a many-to-many with two tables?
Go to Top of Page

AJ217
Starting Member

3 Posts

Posted - 2014-05-05 : 13:53:07
if i was describing lets say classes and students where each student can be in more than one class and each class can have multiple students. Or how about just using Table A by itself. I'm sorry, I'm new to SQL.

Table A
ID Student Class
1 Bob math
2 Tim math
3 Linda english
4 Linda science

Table B
ID Class
10 math
11 science
12 english
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-05-05 : 14:10:08
You can certainly model a one to many with one table, but I wouldn't do it for a number of reasons. The point is that, in general, normalization is a good thing. If you don't use a junction table, then your leaving you data less normalized. If you are not familiar with normalization, then you should look it up! That is one of the fundamental foundations of relational theory. :)
Go to Top of Page

AJ217
Starting Member

3 Posts

Posted - 2014-05-05 : 15:16:52
Ok yeah I'll have to look up normalization with respect to relational theory. Thank you so much.
Go to Top of Page
   

- Advertisement -