当前位置:网站首页>SQLite one line SQL implementation updates if there is one, inserts if there is none, multiple conditions, complex conditions
SQLite one line SQL implementation updates if there is one, inserts if there is none, multiple conditions, complex conditions
2022-06-11 05:32:00 【Trace】
SQLite a line SQL Update if there is one, insert if there is none , Multiple conditions , Complex conditions
Sample code :https://github.com/miqt/MultiProgressKV/blob/master/MultiProgressKV/src/main/java/com/miqt/multiprogresskv/DBHelper.java
For example, you want to implement the following logic
if (db has name == Xiao Ming && height == 170cm)
update ....
else
insert ....
You can refer to the following SQL:
CREATE TABLE [TABLE_NAME](
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[name] TEXT NOT NULL ,
[attr] TEXT NOT NULL ,
[value] TEXT NOT NULL );
CREATE UNIQUE INDEX [TABLE_NAME]
ON [TABLE_NAME](
[name],
[attr]);
CREATE UNIQUE INDEX [TABLE_NAME] Declared that only name, and attr The unique index is calculated only when it is repeated , This applies to scenarios like inserting a book , A book can only have one title and author , And a separate title , And the author himself , It may correspond to many books .
The following statement executes , There are updates , If nothing, the effect of inserting , following SQL Executing multiple times will only produce one row of results , And modify name, perhaps attr Any column , A new one will be inserted .
REPLACE INTO TABLE_NAME
(
name ,
attr ,
value
)
VALUES
(
'《 Journey to the west 》' ,
' author ' ,
' Wu chengen '
) ;
边栏推荐
- Share 𞓜 jointly pre training transformers on unpaired images and text
- Zed2 camera manual
- Preliminary understanding of DFS and BFS
- Tencent X5 kernel initialization failed tbsreaderview not support by:***
- SQLite installation and configuration tutorial +navicat operation
- 1. use alicloud object OSS (basic)
- Deep learning distributed training
- BERT知识蒸馏
- 高斯白噪声(white Gaussian noise,WGN)
- Section II: structural composition characteristics of asphalt pavement (1) structural composition
猜你喜欢

MySQL string to array, merge result set, and convert to array

Number of atoms (easy to understand)

How much current can PCB wiring carry

微信小程序,购买商品属性自动换行,固定div个数,超出部分自动换行

White Gaussian noise (WGN)

Wechat applet uploads the data obtained from database 1 to database 2

推荐一款免费的内网穿透开源软件,可以在测试本地开发微信公众号使用

Combien de courant le câblage des PCB peut - il supporter?

Why is the smart door lock so popular? What about the smart door locks of MI family and zhiting?

Recherche sur l'optimisation de Spark SQL basée sur CBO pour kangourou Cloud Stack
随机推荐
Minimize maximum
mysql字符串转数组,合并结果集,转成数组
AAAI2022-ShiftVIT: When Shift Operation Meets Vision Transformer
Opencv learning path (2-5) -- Deep parsing imwrite function
Games101 job 7-path tracing implementation process & detailed interpretation of code
Wechat applet uploads the data obtained from database 1 to database 2
Intercept file extension
BERT知识蒸馏
Overview of self attention acceleration methods: Issa, CCNET, cgnl, linformer
jvm调优五:jvm调优工具和调优实战
Combing route - Compaction Technology
Zed2 running vins-mono preliminary test
Chapter I: Net architecture (1)
Share 𞓜 jointly pre training transformers on unpaired images and text
截取文件扩展名
Section II: structural composition characteristics of asphalt pavement (1) structural composition
(15) Infrared communication
Recommend a free intranet penetration open source software that can be used in the local wechat official account under test
Share | defend against physically realizable image classification attacks
Cascade EF gan: local focus progressive facial expression editing