【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);
相关推荐
卷心菜不卷Iris24 分钟前
第1章大型互联网公司的基础架构——1.9 LSM Tree
数据库·lsm-tree·互联网大厂·基础架构
GISer_Qing1 小时前
ASP.NET Core 8.0学习笔记(二十七)——数据迁移:Migrations深入与其他迁移命令
数据库·c#·.netcore·entityframework
蓝桉8021 小时前
图片爬取案例
开发语言·数据库·python
Ljw...2 小时前
DeepSeek+Kimi生成高质量PPT
数据库·c++·powerpoint·ppt·deepseek
m0_748240542 小时前
数据库操作与数据管理——Rust 与 SQLite 的集成
数据库·rust·sqlite
生产队队长2 小时前
ThinkPHP:配置Redis并使用
android·数据库·redis
九亿少女无法触及的梦ى2 小时前
uni-app集成sqlite
sqlite·uni-app
致奋斗的我们2 小时前
HAProxy介绍与编译安装
linux·汇编·数据库·mysql·青少年编程·haproxy·openeurler
偏右右2 小时前
UNION 联合查询
数据库·sql
Mr-Apple2 小时前
MySQL的Union和OR查询
android·数据库·mysql