mysqlÖиüÐÂÓï¾äÔõôд
mysql ¸üÐÂÓï¾ä¿ÉÐÞ¸ÄÏÖÓбíÊý¾Ý¡£Ó﷨Ϊ£ºupdate table_name set column1 = value1, column2 = value2, … where condition; °ì·¨ÈçÏ£ºÖ¸¶¨Òª¸üÐÂµÄ±í¡£Ö¸¶¨Òª¸üеÄÁкÍÐÂÖµ¡£Ê¹Óà where ×Ó¾äÖ¸¶¨Ìõ¼þÒÔ¹ýÂËÒª¸üеÄÐС£¿ÉʹÓÃÓÖÃû¼ò»¯ÅÌÎʺÍ×èÖ¹Öظ´±íÃû¡£×ÓÅÌÎÊ¿ÉÓÃÓÚ´ÓÆäËû±í»ñÈ¡¸üÐÂÖµ¡£×èÖ¹ÒÅÍü where ×Ӿ䡢ʹÓÃÎÞЧֵ»ò null Öµ¡£
ÔõÑù׫д MySQL ¸üÐÂÓï¾ä
MySQL ÖеĸüÐÂÓï¾äÓÃÓÚÐÞ¸ÄÏÖÓбíÖеÄÊý¾Ý¡£ËüµÄÓï·¨ÈçÏ£º
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
µÇ¼ºó¸´ÖÆ
Ó﷨˵Ã÷£º
table_name£ºÒª¸üеıíÃû³Æ¡£
column1¡¢column2¡¢…£ºÒª¸üеÄÁÐÃû³Æ¡£
value1¡¢value2¡¢…£ºÒª¸üеÄÐÂÖµ¡£
WHERE condition£ºÓÃÓÚ¹ýÂËÒª¸üеÄÐУ¬Ìõ¼þ¿ÉÒÔÊÇÈκÎÓÐÓÃµÄ SQL ±í´ïʽ¡£
ʾÀý£º
UPDATE customers SET email = 'new_email@example.com' WHERE id = 1;
µÇ¼ºó¸´ÖÆ
´ËÓï¾ä½«±í customers ÖÐ id Ϊ 1 µÄÐÐµÄ email ÁиüÐÂΪ new_email@example.com¡£
¸üжà¸öÁУº
Òª¸üжà¸öÁУ¬Ö»Ð轫Ҫ¸üеÄÁкÍÖµ¶ÔÁ¬ÔÚÒ»Æð¼´¿É£º
UPDATE customers SET email = 'new_email@example.com', phone = '555-123-4567' WHERE id = 1;
µÇ¼ºó¸´ÖÆ
ʹÓÃÓÖÃû£º
ÔÚ¸üÐÂÓï¾äÖпÉÒÔʹÓÃÓÖÃûÀ´¼ò»¯ÅÌÎÊ¡£ÓÖÃûÊDZíµÄÔÝʱÃû³Æ£º
UPDATE customers AS c SET c.email = 'new_email@example.com', c.phone = '555-123-4567' WHERE c.id = 1;
µÇ¼ºó¸´ÖÆ
¸üÐÂ×ÓÅÌÎÊ£º
×ÓÅÌÎÊ¿ÉÓÃÓÚ´ÓÆäËû±íÖлñÈ¡¸üÐÂÖµ£º
UPDATE orders SET product_quantity = (SELECT stock_quantity FROM products WHERE product_id = orders.product_id)
µÇ¼ºó¸´ÖÆ
´ËÓï¾ä½« orders ±íÖÐÿ¸ö¶©µ¥µÄ²úÆ·ÊýÄ¿¸üÐÂΪ²úÆ·±íÖÐÏìÓ¦²úÆ·µÄ¿â´æÊýÄ¿¡£
×èÖ¹³£¼û¹ýʧ£º
ÒÅÍü WHERE ×Ӿ䣺ȷ±£Ê¼ÖÕ°üÀ¨ WHERE ×Ó¾äÒÔ±ÜÃâÒâÍâ¸üÐÂËùÓÐÐС£
ʹÓÃÎÞЧµÄÖµ£º¼ì²éÒª¸üеÄÖµÀàÐÍÊÇ·ñÓëÁеÄÊý¾ÝÀàÐÍÆ¥Åä¡£
ʹÓà NULL Öµ£ºÈôÊÇÁв»ÔÊÐí NULL Öµ£¬Ôò²»ÒªÊ¹Óà NULL ¾ÙÐиüС£
ÒÔÉϾÍÊÇmysqlÖиüÐÂÓï¾äÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡