【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);
相关推荐
zmzmzmalo1 小时前
Linux ELF文件加载与内存管理揭秘
linux·网络·数据库
Super 含8 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?
java·服务器·数据库
ltl9 小时前
向量检索引擎选型:决策树、RAG 回链与开放问题
数据库
坚持学习前端日记9 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
灯澜忆梦9 小时前
【MySQL17】进阶篇 | InnoDB引擎
数据库·mysql
anxiao_m9 小时前
2026制造业云桌面选型攻略,不同生产场景适配方案汇总
大数据·网络·数据库
许彰午10 小时前
# 数据库配拦截器,不用改BPMN
数据库
lv__pf10 小时前
redis【msb 2026金三银四redis上】
数据库·redis·缓存
布莱克60511 小时前
理解数据库聚簇索引:原理、优势与适用场景
数据库·mysql