If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > I need help regarding constraints concept

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-11, 22:04
jetzer jetzer is offline
Registered User
 
Join Date: Jul 2011
Location: Indonesia
Posts: 2
I need help regarding constraints concept

When modeling many-to-many relationship in ERD we transform it into a separated table in relational model. That table must contains PK of both entities and foreign keys to that PKs.

Let's just say I have
entity1 = id, attributes
entity2 = id, attributes

So, the many-to-many relationship would be
relationship = id1, id2, FK id1=entity.id, FK id2=entity2.id, PK id1,id2

I don't know whether we need to add PK constraint to that table or not. I suppose we need because a table need a PK. Is my way above the correct way to do many-to-many relationship?

Or make it like this?
relationship = id, id1, id2, FK id1=entity.id, FK id2=entity2.id, PK id
Reply With Quote
  #2 (permalink)  
Old 07-14-11, 05:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
no, you should not have a separate id for the PK

do it the first way you said --

CREATE TABLE relationship
( id1 INTEGER NOT NULL
, id2 INTEGER NOT NULL
, PRIMARY KEY ( id1, id2 )
);
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On