For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > April 2004 > mysql foreign key syntax / tutorial









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author mysql foreign key syntax / tutorial
Uzi Klein

2004-04-21, 6:34 pm

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.
Torsten Roehr

2004-04-21, 6:34 pm

"Uzi Klein" <uzi@bmby.com> wrote in message
news:005901c427ed$526e76c0$f805a8c0@p4...
> 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/I...onstraints.html

Regards,
Torsten Roehr
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com