当前位置:网站首页>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
- (15) Infrared communication
- 【深入kotlin】 - Flow 进阶
- Dongmingzhu said that "Gree mobile phones are no worse than apple". Where is the confidence?
- QT Road (2) -- HelloWorld
- In the future, how long will robots or AI have human creativity?
- How to make lamps intelligent? How to choose single fire and zero fire intelligent switches!
- (十五)红外通信
- Recherche sur l'optimisation de Spark SQL basée sur CBO pour kangourou Cloud Stack
- 在未来,机器人或 AI 还有多久才能具备人类的创造力?
猜你喜欢

Recommend a free intranet penetration open source software that can be used in the local wechat official account under test

Number of atoms (easy to understand)

Maximum number of points on the line ----- hash table solution
![[aaai 2021 timing action nomination generation] detailed interpretation of bsn++ long article](/img/28/d69a7583036a2076facffcf9098d7e.jpg)
[aaai 2021 timing action nomination generation] detailed interpretation of bsn++ long article

微信自定义组件---样式--插槽

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

深度学习分布式训练

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

Share | guide language image pre training to achieve unified visual language understanding and generation

Reverse thinking: making cartoon photos real
随机推荐
Multi threading tutorial (XXIV) cas+volatile
Course design summary
1.使用阿里云对象OSS(初级)
PageHelper page 2 collections in the same interface
Preliminary test of running vins-fusion with zed2 binocular camera
智能门锁为什么会这么火,米家和智汀的智能门锁怎么样呢?
截取文件扩展名
Start the project using the locally configured gradle
Common methods of tool class objectutil
Section III: structural characteristics of cement concrete pavement
Cross modal retrieval | visual representation learning
Section V: Recycling Application of asphalt pavement materials
BERT知识蒸馏
Big meal count (time complexity) -- leetcode daily question
The programmers of a large factory after 95 were dissatisfied with the department leaders, and were sentenced for deleting the database and running away
使用acme.sh自动申请免费SSL证书
Opencv learning path (2-1) -- Deep parsing imread function
PCB走线到底能承载多大电流
Multi threading tutorial (XXIV) cas+volatile
Topological sorting