Jump to content

mysql tables relationships


itazev

Recommended Posts

Hi there!

 

I recently migrated from ms-access to php/mysql ("a small step for the men, a huge step for the humanity"  ;D ) and now I'm facing an issue on tables relationship . I don't know too much of sql language, so I googled and searched in on books for mysql relationships InnoDB. I found some slight explanations. In a few words, how can I set up a relationship between two tables whether (lets say...)

 

table clients

- clientID

- client_name

 

table products

- clientID

- product_name

 

In this case i'd like to link clientID from clients to clientID on products and on deleting a client, its products will be deleted automatically, also a product entry must have an associated entry on clients.

I was thinking about a database modeling software but i want to learn the sql statements.

 

I appreciate your help!

 

 

 

Link to comment
Share on other sites

What you're looking for are foreign keys and triggers.  Foreign keys can ensure referential integrity (i.e. a record in table x must have a matching value in table y).  Triggers can be used to delete from one table when a deletion is done from another.  Check your mysql version to see which features are available (has mysql ever had triggers?).

 

MS Access has foreign keys.  You create them when viewing "Relationships" and draggings fields across tables so you have lines matching them up.

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.