更新 SQL 中的多条记录

2022-01-17 00:00:00 sql-update sql sql-server

如何使用 SQL 更新单个语句中的多条记录?:

How can i update multiple records in a single statement like this with SQL?:

UPDATE records
   SET name='abc' where id=3,
   SET name='def' where id=1

推荐答案

您可以简单地将更新与 case 语句结合起来,例如

You can simply combine an update with a case statement such

UPDATE records
   SET name =
     CASE
       WHEN id = 3 THEN 'abc'
       WHEN id = 1 THEN 'def'
       ELSE name
     END

相关文章