ziiweb ziiweb - 7 months ago 9
SQL Question

SQL: what kind of relation (1:1, 1:m, m:m,...) there is between this two tables?

what kind of relation (1:1, 1:m, m:m, whatever) there is between this two tables?

CREATE TABLE IF NOT EXISTS `my_product` (
`id` int(11) NOT NULL auto_increment,
`price` float default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `my_product_i18n` (
`id` int(11) NOT NULL,
`culture` varchar(7) NOT NULL,
`name` varchar(50) default NULL,
PRIMARY KEY (`id`,`culture`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


ALTER TABLE `my_product_i18n`
ADD CONSTRAINT `my_product_i18n_FK_1` FOREIGN KEY (`id`) REFERENCES `my_product` (`id`);

Answer

It is 1:m you can have several different culture in my_product_i18n connected for each id.

Edit:
It is PRIMARY KEY ('id','culture') in conjunction with the constraint that tells that you can have many my_product_i18n.