Linked Tables

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Linked Tables

Postby SirChick » 23. July 2007 17:50

How do i link tables using a particular field?

For example i have my users info each unique by the user ID which is primary key also.

If i wanted to link the userID to more info on a different table how is this done? do i just make a field in the new table exactly the same name as the other table for userID and it automatically connects the two ?


So like table one would have userid as its first field
as would table two and both have them as primary key would this make them link ?
SirChick
 
Posts: 68
Joined: 19. June 2007 15:03
Operating System: Windows 7 64 bit

Postby outlaw » 24. July 2007 23:58

- they will only "link" if you link them using a join operation
- if you name both fields the same (you should) then use natural join:
Code: Select all
select * from users natural join subscriptions
  --equivalent to--
select * from users u join subscriptions s on (s.userID = u.userID)



btw:
- the primary key doesn't have to be the first field
- if you will be dealing with many updates/deletes then you should consider changing some tables to innoDB. You can then map relations like this, and specify actions on update,delete operations
ie: if you delete a user, also delete everything associated with him in other tables
outlaw
 
Posts: 18
Joined: 08. June 2007 23:01


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 55 guests