gpt4 book ai didi

php - Mysql 函数 : Insert if not exist or updated

转载 作者:行者123 更新时间:2023-12-01 00:13:16 24 4
gpt4 key购买 nike

我有一个小问题——我如何在 mysql 中编写一个函数来插入一条记录,如果它不存在或者它存在的情况然后说例如记录被更新为默认值的新副本应重新插入记录,将更新后的记录留在表中。让我举一个小场景,在抨击我之前请仔细阅读,我会尽力解释:

table name= Computer.
Columns(2) = comp_id(Auto-increment), comp_name.

我想要在表中的默认数据=

comp_id= 1, comp_name='Dell'

现在,如果我应该将此信息更新为:

comp_name='HP'

该函数应自动添加以前的记录:

comp_name='Dell'

我想过使用 update if not exist 但我正在阅读博客,他们说 Mysql 不支持 update if not exist。如果您能提供任何建议,我将不胜感激。

最佳答案

你想在 mysql 中插入重复更新。

http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html

关于php - Mysql 函数 : Insert if not exist or updated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12101651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com