Jump to content

Bridging Table - To use or not?


mds1256

Recommended Posts

Just wondering what people's views are on bridging tables.

 

Should I use them rather than creating a new field in the table to reference the other tables row number.

 

 

e.g.

 

Bridging table method:

 

Users table:

userID

userName

userPassword

1

abcd

1234

 

 

Address table:

AddressID

houseNo

streetName

postCode

5

52

New Street

AA2 4DD

 

Bridge table:

bridgeID

userID

addressID

1

1

5

 

 

 

 

 

Same table method:

 

Users table:

userID

userName

userPassword

addressID

1

abcd

1234

5

 

 

Address table:

AddressID

houseNo

streetName

postCode

5

52

New Street

AA2 4DD

 

Link to comment
Share on other sites

@mds1256: The method to choose depend on the kind of relationship that you want to implement

 

in your example the bridge method will be useful if your user could have 0 or more addresses (Postal, Commercial, etc)

the "same table" option that you show imply that the user will have only 1 (or 0) address.

Link to comment
Share on other sites

@mds1256: The method to choose depend on the kind of relationship that you want to implement

 

in your example the bridge method will be useful if your user could have 0 or more addresses (Postal, Commercial, etc)

the "same table" option that you show imply that the user will have only 1 (or 0) address.

 

Very true!

 

but if you change the location of the matching id field onto the address table you could have multiple address entries with the same userID and it would give you the same result

 

So what is the benefit, I guess if you want a many to many relationship this will justify it

Link to comment
Share on other sites

A user can have multiple addresses (home, work, ..). And multiple users can have the same address (colleagues, family members, students in the same house, ..). But you don't want to share addresses among users because when one edits his address, your packages may end up with the wrong customer. The relation therefor is:

 

User (user_id, ..)

Address (address_id, user_id, ..)

 

You don't need the bridge table because each address is unique for each customer even if multiple customers live on the same address.

Link to comment
Share on other sites

Ignace gave you some points... but again, the relation that you implement is going to be determined by your business model.. sometimes you want/need to have multiples users (related of course) sharing the same address or addresses ... depend on your specific needs.

 

In the case that Ignace is explaining, if you have 2 related users sharing the same address(es) you will be duplicating information in your address table, therefore the table will be  no normalized (which could be an option too).

 

Example (as per your last post and apparently same Ignace idea):
Users
1 Jhon Doe
2 Mary Doe (spouse)

Address
id address        city     zip       addresstype           userid
1 kitty Road 10 Atlanta 23245     1(home)                   1
2 kitty Road 20 Atlanta 23248     2(comm)                   1
3 kitty Road 10 Atlanta 23245     1(home)                   2

 

instead of (using a bridge)

 

Example (as per your last post and apparently same Ignace idea):
Users
1 Jhon Doe
2 Mary Doe (spouse)

Address
id address        city     zip       
1 kitty Road 10 Atlanta 23245     
2 kitty Road 20 Atlanta 23248    
  

User-Address
id  userid  address-id   type
1     1              1             1
2     1              2             2
3     2              1             1

 

Link to comment
Share on other sites

@mikosiko Sharing addresses is not an option in this case, since:

 

Assume I life on SesameStreet 7 with other students and 3 students are a customer:

 

SesameStreet 7 | Student #1

SesameStreet 7 | Student #2

SesameStreet 7 | Student #3

 

Now Student #1 moves to Maryland 10 since only one record exists for SesameStreet 7 all are updated to Maryland 10:

 

Maryland 10 | Student #1

Maryland 10 | Student #2

Maryland 10 | Student #3

 

One UPDATE just messed up your entire DB. I could even start adding addresses and then change them to my current address, now all your shipments are send to my home address (while I didn't pay for any of them).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.