Re: Re: mysql foreign keys
| From: | Uzi Klein | Date: | Wed, 21 Apr 2004 22:43:29 +0000 |
| Subject: | Re: Re: mysql foreign keys | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-34028@lists.php.net to get a copy of this message | ||
> Hi.
>
> Any body got an idea how to use hte foreign keys in mysql innodb tables
> and how whould the change affect the performance of the server?
>
> lets say i have Items table, Clients table, and Sales table
> the Sales table always stores ClientID and ItemID
> but not every client/item is there
> a sale can be deleted without harming the client
> nor the item.
>
> i guess (not sure at all) it should go like :
>
> ALTER TABLE Sales
> ADD FOREIGN KEY ClientID(ClientID)
> REFERENCES Clients(ClientID)
> ON DELETE RESTRICT;
>
> ALTER TABLE Sales
> ADD FOREIGN KEY ItemID(ItemID)
> REFERENCES Items(ItemID)
> ON DELETE RESTRICT;
>
> Am I correct?
>
> thanks.
Take a look here:
http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html
Regards,
Torsten Roehr
I did the test's and it seems ok, i just want a second opinion,
cause of my lack in experience.
I just want to be sure that's the right and best way of doing it.
btw, the indexes are already set for select joins etc.
Thanks