本文作者:kris

mysql 的replace into实例详解-

kris 2025-02-02 18:15:16 2
mysql 的replace into实例详解-摘要: mysql的replaceinto实例详解?1、首先判断数据是否存在;2、如果不存在,则插入;3、如果存在,则更新。在SQL Server中可以这样处理:if not exists...

mysql的replaceinto实例详解?

1、首先判断数据是否存在;

mysql 的replace into实例详解-

图片来源:网络

2、如果不存在,则插入;

3、如果存在,则更新。在SQL Server中可以这样处理:if not exists (select 1 from t where id = 1)? insert into t(id, update_time) values(1, getdate()) else update t set update_time = getdate() where id = 1那么 MySQL 中如何实现这样的逻辑呢?MySQL 中有更简单的方法: replace intoreplace into t(id, update_time) values(1, now());或replace into t(id, update_time) select 1, now();

文章版权及转载声明

作者:kris本文地址:https://www.damoyx.com/p/29870.html发布于 2025-02-02 18:15:16
文章转载或复制请以超链接形式并注明出处大漠游侠网

阅读
分享