本文介绍了MySQL INSERT,如果存在,则更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用两列config_name和config_value建立一个配置表.我在一条语句中插入多行:
I'm building a config table with two columns, config_name and config_value. I insert multiple rows in one statement:
INSERT INTO ".$dbPrefix."config (config_name,config_value) VALUES ('domain','$domain'), ('forest_root','$fr_if'), ('userGroup','$userGroup'), ('adminGroup','$adminGroup');config_name列是主键.如果config_name已经存在,我将如何更改此语句以自动更新config_value?
The config_name column is a primary key. How would I change this statement to automatically update the config_value if the config_name already exists?
推荐答案您可以尝试使用以下语法:
You could try this syntax:
INSERT INTO table (field) VALUES (value) ON DUPLICATE KEY UPDATE field=value可以在此处找到文档.
更多推荐
MySQL INSERT,如果存在,则更新
发布评论