Jump to content

Archived

This topic is now archived and is closed to further replies.

im1hunt

db relationships

Recommended Posts

Ok, I am using phpmyadmin to create my MySQL data base and it is all working properly. I have normalised the data in my table and have all the feilds set up but I am unsure as to how I create the relationships butween the tables in my db. I know that in microsoft access all you do is open a window with the tables and drag the mouse over the fields you want to join, but I dont know how to do it in MySQL.

 

can anyone tell me?

Share this post


Link to post
Share on other sites

I might be wrong here and I am hoping I am becuase I\'ve been doing it this way for some time now...

 

There is no way to create a relationship between tables in MySQL. The relationships must be upheld through the code.

 

I believe they are planning to fix this as of MySQL 4

Share this post


Link to post
Share on other sites

you can specify foreign keys but it doesn\'t actually link them together - it\'s more of a textual reference when someone looks at your db structure. do you know how to join the tables in a query?

Share this post


Link to post
Share on other sites
do you know how to join the tables in a query?

I myself am a bit unsure of how to do this... would you mind pointing me in the right direction?

Share this post


Link to post
Share on other sites

You don\'t actually setup relationships, but it is instead in how you query the database. If you have a SQL book, just look at queries and this will become quite clear. You could also look at JOIN in the SQL manual.

Share this post


Link to post
Share on other sites

table_name: cities

id | name

1 | charlotte

2 | new york

 

table_name: people

id | name | city

1 | bob | 1

2 | bill | 2

 

select p.name, c.name from cities c , people p where p.city=c.id;

(this is off my head - i may have something wrong but i hope you catch the general idea)

 

would return:

 

bob | charlotte

bill | new york

 

it returns the person\'s name and the city\'s name where the city field was equal to the cities id.

Share this post


Link to post
Share on other sites

I have been searching the internet and books trying to find an actual explanation of how to query a DB using something along the lines of relationships. I\'m also an Access & Filemaker Pro user learning MySQL, and learning new terminology and structure is killing me!

 

Thank you Effigy for spelling it out for us converts!

 

:D:D:D:D:D

Share this post


Link to post
Share on other sites

Can someone explain what JOIN actually does? Does it combine tables? Or just reference them?

Share this post


Link to post
Share on other sites

×

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.