【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);
相关推荐
AAA修煤气灶刘哥7 小时前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
RestCloud11 小时前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术14 小时前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
可涵不会debug18 小时前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom18 小时前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
麦兜*18 小时前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
Slaughter信仰18 小时前
深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)第十章知识点问答(10题)
java·jvm·数据库
麦兜*18 小时前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring
-Xie-19 小时前
Mysql杂志(十六)——缓存池
数据库·mysql·缓存