如何在单个查询中更新具有多个值的列

时间:2017-06-02 04:12:18

标签: sql

实施例

Update A 
set userid - (1, 2, 3), userrolesid - (1, 2, 3) 
where id - 40

2 个答案:

答案 0 :(得分:0)

使用以下查询进行多次更新:

  UPDATE A SET userid = '1,2,3' , userrolesid = '1,2,3'
  WHERE id = 40

注意:两个更新列都必须是VARCHAR数据类型。

答案 1 :(得分:0)

WITH Tmp(id, px, py) AS (VALUES(id1, newsPosX1, newPosY1), 
                               (id2, newsPosX2, newPosY2),
                               ......................... ,
                               (idN, newsPosXN, newPosYN))

UPDATE TableToUpdate 
SET posX = (SELECT px
            FROM Tmp
            WHERE TableToUpdate.id = Tmp.id),
    posY = (SELECT py
            FROM Tmp
            WHERE TableToUpdate.id = Tmp.id)
WHERE id IN (SELECT id FROM Tmp)