开发者

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,
  `cultur开发者_运维问答e` 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`);


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜