【SQLite】sqlite | insert插入存在即更新

一、概述

需求开发有需要处理insert的场景,索引字段存在时,容易冲突;必要时可以进行更新

二、更新方案

1、方案一:insert into ...on conflict (索引字段) do update set...

复制代码
insert into t_device values (1, '2', '2', '2', 'now') on conflict (id) do UPDATE set device_type = '2', device_name = '2', create_time = 'now';

2、方案二:replace into ...

复制代码
replace into t_device values (1, '2', '3', '3', 'now2');

3、t_device

复制代码
create table t_device(
id integer primary key autoincrement,
device_code text,
device_type text,
device_name text,
create_time text);
相关推荐
数智化管理手记4 小时前
精益生产中的TPM管理是什么?一文破解设备零故障的密码
服务器·网络·数据库·低代码·制造·源代码管理·精益工程
翊谦4 小时前
Java Agent开发 Milvus 向量数据库安装
java·数据库·milvus
難釋懷5 小时前
OpenResty实现Redis查询
数据库·redis·openresty
别抢我的锅包肉6 小时前
【MySQL】第四节 - 多表查询、多表关系全解析
数据库·mysql·datagrip
Database_Cool_6 小时前
OpenClaw-Observability:基于 DuckDB 构建 OpenClaw 的全链路可观测体系
数据库·阿里云·ai
刘~浪地球6 小时前
Redis 从入门到精通(五):哈希操作详解
数据库·redis·哈希算法
zzh0817 小时前
MySQL高可用集群笔记
数据库·笔记·mysql
Shely20177 小时前
MySQL数据表管理
数据库·mysql
爬山算法7 小时前
MongoDB(80)如何在MongoDB中使用多文档事务?
数据库·python·mongodb
APguantou7 小时前
NCRE-三级数据库技术-第2章-需求分析
数据库·需求分析