简体   繁体   English

根据SQL中的主键更新一列的多行

[英]Update multiple rows of one column based on primary key in SQL

I know that I want to update only one row from a column I use this statement 我知道我只想更新使用此语句的列中的一行

UPDATE Customers
    SET ContactName = 'Alfred Schmidt'
    WHERE CustomerID = 1; 

but what if I want to update multiple for example 5 rows based on primary key value? 但是如果我想基于主键值更新多个(例如5行)怎么办?

The IN operator allows you to specify multiple values in a WHERE clause. IN运算符允许您在WHERE子句中指定多个值。

Example: 例:

As in this: 像这样:

SELECT *
FROM Customers
WHERE Customer_id IN (5000, 7000, 8000, 9000);

format: 格式:

expression IN (value1, value2, .... value_n);

In the mentioned case : 在上述情况下:

UPDATE Customers
    SET ContactName = 'Alfred Schmidt'
    WHERE CustomerID IN(12, 156);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM