SQL:这两个表之间有什么样的关系(1:1, 1:m, m:m,...)? [英] SQL: what kind of relation (1:1, 1:m, m:m,...) there is between this two tables?

查看:40
本文介绍了SQL:这两个表之间有什么样的关系(1:1, 1:m, m:m,...)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个表之间有什么样的关系(1:1、1:m、m:m,等等)?

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:m 你可以在 my_product_i18n connected 中为每个 有几个不同的 cultureid.

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


PRIMARY KEY ('id','culture') 结合约束告诉你可以有很多 my_product_i18n.


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

这篇关于SQL:这两个表之间有什么样的关系(1:1, 1:m, m:m,...)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆