问题
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`);
回答1:
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
.
回答2:
1 to "maybe" - there's no guarantee that there will be a row in my_product_i18n, and the composite primary key of id and culture mean that you could have multiple rows for a given id, provided that those rows are of different cultures.
回答3:
This is a 1:M relationship. One row in my_product
can have 0, 1, or more rows in my_product_i18n
based off of the culture
column.
来源:https://stackoverflow.com/questions/3998545/sql-what-kind-of-relation-11-1m-mm-there-is-between-this-two-tables