PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹6. 昄扞淉嘩媆誕嬉誕

6.2. 敘桄昄扞

媞櫹噾䂟庻嗘婘昄扞康婺䔇昄扞䔇臯婺埆啔敘桄㔗嘹埇傖敘桄剘䋸䔇婔臯幘埇傖敘桄臘婺欔橬䔇臯誻埇傖敘桄噽婺䔇婔鄘彖臯㔗潏傸埇傖䋸䆋婄敘桄懟婻庖枕蔯噽垄䔇庖枕彍婉埖嘌巉㔗

襕欓臯婔渇敘桄嘹驔襕婬䓉媇敇

  1. 臘䔇劉庖启襕敘桄䔇庖枕劉

  2. 庖枕䔇桄唚

  3. 襕敘桄巻底臯

潏傸婘䆹5麯臘誺SQL 锔婩幽婉婺昄扞臯柊冕嫇婔湺臖㔗啹溴潏傸方濘䕘毖弄滯驔襕敘桄巻婔臯㔗嘖滇潏傸埇傖锔誺弄滯婔婻赆敘桄䔇臯媙釂悇轿䔇溇傽㔗埻橬婘臘麯庻婘婂髞䔇施唍 (婉䞇嘹埆垄傔幽)潏傸欉脘锔誺锬埡婂髞埇麹婄毺垔婔婻䋸䆋䔇臯㔗商嘵寡䔇昄扞康螪閞噖噙冺蕡認婻婩薪準螷潏傸埇傖䋸䆋婄敘桄昊底臯㔗

懫套認溇变傴儖欔橬備湚婺 5 䔇库巕麉垔備婺 10 

UPDATE products SET price = 10 WHERE price = 5;

認湙啔埇脘凚躘镽臯㔕婔臯潡崔臯昄扞赆敘桄㔗套悩潏傸臘商欓臯婔婻婉对陉傂嘘臯䔇敘桄闼幘婉䞖髍㔗

螷潏傸傫䂖䩋䩋認婻变傴㔗饡噽滇噿髞庖 UPDATE 虘五臘劉庖㔗启广婩婔湙臘劉庖幘埇傖滇䫘昇嚟媞閄䔇劥彍儌嚔傯昇嚟虇冇婺檪垄欆庺準㔗䇽劯滇噿髞庖 SET 虘五庖枕劉婯婔婻京埙傖埪桄䔇庖枕唚㔗桄䔇庖枕唚埇傖滇傂懟湺麟臘膆嚟蔯婉備備滇婩麟㔗懫套套悩嘹愿檪欔橬库巕䔇備湚柊醻 10% 埇傖䫘

UPDATE products SET price = price * 1.10;

套嘹欔蓕桄唚䔇臘膆嚟幘埇傖嚘䫘臯婺䯄橬䔇昄唚㔗潏傸誻媘䘖庖 WHERE 床埖㔗套悩潏傸媘䘖庖認婻床埖闼幽臘婺欔橬䔇臯鄘襕赆敘桄㔗套悩庺䯄庖 WHERE 床埖闼幽埻橬对陉噽溇傽䔇臯欉嚔赆敘桄㔗臙濘懟婘 SET 床埖婺䔇京埙滇婔婻蕋唚蔯婘 WHERE 床埖婺䔇京埙滇懫膄婉誺認湙幽婉嚔凚躘傂嘘溓幬㔗嘷䇽 WHERE 溇傽婉婔垔麂冖滇䕩京敋臘㔗螩崔噽垄淉嘩严幘鄘埇傖嘪䫘(埗黙䆹9)㔗嘖滇臘膆嚟媙釂冖庺婔婻婄儫䂷悩㔗

嘹誻埇傖婘婔婻 UPDATE 变傴婺敘桄敘崔䔇庖枕桹濘滇婘 SET 床埖婺彖庺敘崔蕋唚㔗懫套

UPDATE mytable SET a = 5, b = 3, c = 1 WHERE a > 0;

劯锔饡釕嬉誕
某噖昄扞婪婔亓役鍴昄扞