Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql中一个表中的多个外键与另一个表之间的连接_Mysql_Foreign Keys - Fatal编程技术网

mysql中一个表中的多个外键与另一个表之间的连接

mysql中一个表中的多个外键与另一个表之间的连接,mysql,foreign-keys,Mysql,Foreign Keys,我的数据库中有两个表:user和call。用户存在3个字段:id、姓名、号码和呼叫:id、来源、目的地、参考、日期 我需要在我的应用程序中监视通话。上面的3''字段实际上是用户ID号 现在我想知道,我可以将表user中id字段的3个字段外键元素设置为吗?是-可以;-) 只需定义所有三个外键,以引用用户中的id列类似的内容即可: ALTER TABLE call ADD CONSTRAINT fk_call_source_user FOREIGN KEY (source) REFERENCES

我的数据库中有两个表:user和call。用户存在3个字段:id、姓名、号码和呼叫:id、来源、目的地、参考、日期

我需要在我的应用程序中监视通话。上面的3''字段实际上是用户ID号

现在我想知道,我可以将表user中id字段的3个字段外键元素设置为吗?

是-可以;-)


只需定义所有三个外键,以引用
用户
中的
id

类似的内容即可:

ALTER TABLE call 
ADD CONSTRAINT fk_call_source_user FOREIGN KEY (source) 
REFERENCES user (id)

ALTER TABLE call 
ADD CONSTRAINT fk_call_destination_user FOREIGN KEY (destination) 
REFERENCES user (id) 

ALTER TABLE call 
ADD CONSTRAINT fk_call_referred_user FOREIGN KEY (referred) 
REFERENCES user (id)
更改表调用

添加外键(Sourceid)引用源(Id)

外键(DesId)引用目标(Id)