我想更新多个列我试过这种方式,但不幸的是它没有工作可以任何人帮助我吗?

时间:2016-03-09 03:35:30

标签: sql sql-update multiple-columns

UPDATE business
    SET business_id=4,contact=Mario Luigi,position=plumber,
    SET business_id=3,email=www.grankelly.org,
    SET business_id=2,contact=Homer Simpson,position=Purchasing Engineer,address=1234 Main St,city=Springfield,state=IL,Postal=19382,phone=555-555-5555,email=www.cajundelights-midwest.com,
    WHERE

1 个答案:

答案 0 :(得分:0)

这些必须是单独的更新语句,因为您无法使用不同的值更新多个记录。例如,您将business_id更新为不同的值,因此每个语句都需要是一个单独的查询。您还需要在字符串值周围加上单引号。

/*Query 1:*/
UPDATE business
        SET business_id=4,contact='Mario Luigi',position='plumber'
WHERE ...

/*Query 2:*/
UPDATE business
        SET business_id=3,email='www.grankelly.org' WHERE ...

/*Query 3*/
UPDATE business 
SET business_id=2,contact='Homer Simpson',position='Purchasing Engineer',address='1234 Main St',city='Springfield',[state]='IL',Postal='19382',phone='555-555-5555',email='www.cajundelights-midwest.com' WHERE ...