MySQL INSERT,如果存在,则更新 [英] MySQL INSERT else if exists UPDATE
本文介绍了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,如果存在,则更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文