[英]UPDATE set table with 3 different tables foreign key and primary key
I have two different tables. 我有两个不同的表。
Department table 部门表
//Department
D# DNAME
-------------------
1 SALES
2 ACCOUNTING
3 GAMES
5 SPORTS
Employee Table 员工表
//Employee
E# D#
-----------
1 3
2 2
3 5
4 5
Now using Update statement , update the D#=5 to D#=3; 现在使用Update语句,将D#= 5更新为D#= 3;
Currently using this statement 当前正在使用此语句
UPDATE EMPLOYEE SET D# = 3 WHERE D# = 5;
But then i trying to learn that if i don't want update using D#, but want to update using the DNAME which mean E# from SPORT will change to GAMES , what should i do to solve it. 但是后来我试图了解一下,如果我不想使用D#进行更新,而是想使用DNAME进行更新,这意味着SPORT的E#将变为GAMES,我应该怎么做才能解决它。
You want the multi table update
您想要multi table update
Something along the lines of: 类似于以下内容:
update employee e
join department d using (d#)
set e.d# = 3
where d.dname = 'SPORTS';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.