SQL用于更新来自不同表的记录 [英] SQL to update records from different tables

查看:68
本文介绍了SQL用于更新来自不同表的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试更新缺少某些数据的表,但是更新语句有问题。



我有以下表格和数据:



客户表1:



客户ID:1234

客户名称:John

客户联系人:0189541145



订单表2:

CustomerId:空白

订单编号:12345

订单类型:纸



如何更新表格还有客户ID:



Hi
I am trying to update a table which is missing some data, but having problems with the update statement.

I have the following tables and data:

Customer table 1:

CustomerID: 1234
CustomerName: John
CustomerContact: 0189541145

Orders table 2:
CustomerId: blank
OrderNumber: 12345
OrderType: paper

how can i update the table to also have customer ID:

update Orders
set customerID = c.CustomerID
from Customer
where customerID = 12345

推荐答案

由于客户和订单表之间没有任何共同点且客户ID为空,因此无法设置 null 客户ID自动计算值。



你必须手动使用订单ID更新Order表中的行 -

更新订单设置customerId = ??订货号= 123456
Since there is nothing common between the customer and orders table and the customer id is blank, there is no way to set null customer ids to a value automatically.

You have to manually update rows in the Order table by using the order id -
Update Orders set customerId = ?? where Order Number = 123456


这篇关于SQL用于更新来自不同表的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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