You are here: Re: [PHP] novice: table design FOREIGN key « PHP « IT news, forums, messages
Re: [PHP] novice: table design FOREIGN key

Posted by Michael Satterwhite on 10/20/85 11:16

tony yau wrote:
| Hi All
|
| Thanks for all your comments on my previous mail, very much
appreciated.
| I'm stuck again!
| I've created the following lookup table for m <-> m relationship
between
| a Group and a Contact table.
|
| CREATE TABLE Group_Contact(
| GroupID INT NOT NULL,
| ContactID INT NOT NULL,
|
| Index (GroupID),
| FOREIGN KEY (GroupID) REFERENCES Group (PKey) ON DELETE CASCADE,
| Index (ContactID),
| FOREIGN KEY (ContactID) REFERENCES Contact (PKey) ON DELETE CASCADE
| ) TYPE=InnoDB COMMENT='Group to Contact lookup';
|
| what do I need to do to ensure only unique (GroupID,ContactID) pair can be
| inserted into the table?

This question is really a MySQL question. You might want to join their
mailing list as you'll get better answers for this type of question there.

That said: The easiest way would be to make GroupId, ContactID a unique
index. In this case, primary key would be OK. Add the statement

Primary Key(GroupID, ContactId),

just before the first "Index" statement.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация