MySQL INSERT,如果存在,则更新

编程入门 行业动态 更新时间:2024-10-28 02:23:51
本文介绍了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,如果存在,则更新

本文发布于:2023-10-18 03:02:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502886.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:则更   MySQL   INSERT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!