Jump to content


Photo

db relationships


  • Please log in to reply
7 replies to this topic

#1 im1hunt

im1hunt
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 26 February 2003 - 11:37 AM

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?

#2 deathead

deathead
  • Members
  • Pip
  • Newbie
  • 4 posts
  • LocationSunrise/Coral Springs FL, USA

Posted 26 February 2003 - 04:38 PM

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
~Deathead [br]"You know a conjurer gets no credit when once he has explained his trick and if I show you too much of my method of working, you will come to the conclusion that I am a very ordinary individual after all" - Sherlock Holmes

#3 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 26 February 2003 - 05:04 PM

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?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#4 deathead

deathead
  • Members
  • Pip
  • Newbie
  • 4 posts
  • LocationSunrise/Coral Springs FL, USA

Posted 26 February 2003 - 05:07 PM

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?
~Deathead [br]"You know a conjurer gets no credit when once he has explained his trick and if I show you too much of my method of working, you will come to the conclusion that I am a very ordinary individual after all" - Sherlock Holmes

#5 phpmonkey

phpmonkey
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationSt. Louis

Posted 26 February 2003 - 07:02 PM

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.

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 26 February 2003 - 07:10 PM

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.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 stephtort

stephtort
  • Members
  • Pip
  • Newbie
  • 9 posts
  • Locationnorth of 8 Mile

Posted 21 November 2003 - 10:12 PM

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
*****************************[br]Stephanie

#8 stephtort

stephtort
  • Members
  • Pip
  • Newbie
  • 9 posts
  • Locationnorth of 8 Mile

Posted 21 November 2003 - 10:14 PM

Can someone explain what JOIN actually does? Does it combine tables? Or just reference them?
*****************************[br]Stephanie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users