MySQL Forums
Forum List  »  InnoDB

Re: Foreign Key referencing multiple tables: possible?
Posted by: Vinod Sugur
Date: November 28, 2008 05:49AM

Hi Samuel,

We can create Foreign key referencing multiple tables but the value which we are going to insert MUST present in ALL the referenced tables.

Example :

CREATE TABLE `test`.`d` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_all` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_d_u_1` FOREIGN KEY (`id`) REFERENCES `a_u` (`id`),
CONSTRAINT `FK_d_u_2` FOREIGN KEY (`id`) REFERENCES `b_u` (`id`),
CONSTRAINT `FK_d_u_3` FOREIGN KEY (`id`) REFERENCES `c_u` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

If i insert row values 1,1 in table d then the value 1 MUST be present in a_u, b_u and c_u tables.


Regards,
Vinod

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Foreign Key referencing multiple tables: possible?
2757
November 28, 2008 05:49AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.