【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);
相关推荐
健康平安的活着2 分钟前
redis 中IO多路复用与Epoll函数
网络·数据库·redis
江凡心15 分钟前
Qt 每日面试题 -5
服务器·数据库·qt·学习·面试
HumoChen991 小时前
MySQL tinyint(1)类型数据在经过flink cdc同步到doris后只有0/1问题定位与解决
数据库·mysql·flink
阿乾之铭1 小时前
MySQL数据查询(基础)
数据库·sql·mysql
Yan-D2 小时前
【Redis 源码】2项目结构说明
数据库·redis·缓存
DieSnowK2 小时前
[Redis][事务]详细讲解
数据库·redis·缓存·事务·redis事务·新手向·事务操作
开源哥662 小时前
【含文档】基于Springboot+微信小程序 的中心医院用户移动端(含源码+数据库+lw)
数据库·spring boot·微信小程序
rubyw2 小时前
SQL:如果字段需要排除某个值但又有空值时,不能直接用“<>”或not in
服务器·数据库·sql
TuringSnowy2 小时前
SQL_having_pandas_filter
数据库·笔记·sql·mysql·pandas
奈李喔2 小时前
综合实践:JPA+Thymeleaf 增删改查
数据库