请问sqlite的"插入或替换”包含自动增量主键的工作原理 [英] Does sqlite "insert or replace" works with AUTOINCREMENT primary key

查看:100
本文介绍了请问sqlite的"插入或替换”包含自动增量主键的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在,我已创建了一个表名SectionDetails的数据库。
在这张表我已经设置ID与 AUTOINCREMENT 主键property.And我正在插入我的数据到这个表。

I have a database in which i have created one table with name "SectionDetails". In this table i have set "id" as a primary key with AUTOINCREMENT property.And i am inserting my data into this table.

不过,我来到了,我需要检查,如果记录我正在插入已经场景present与否(如果记录是那么present具有相同的价值观取代它,或跳过它,如果记录没有present然后插入新的)。

However, i came to the scenario where i need to check if record i am inserting is already present or not(if record is present then replace it with same values or skip it,And if record is not present then insert new one ).

但是,当我试图插入与相同的列值的记录,它增加了主键,然后重新插入,而不是替换同一行。

But when i tried to insert record with same column values, it increases the primary key and insert the same row again instead of replacing.

所以,我的问题是 -
请问sqlite的插入或更换包含自动增量主键的作品?

So, my question is- Does sqlite "insert or replace" works with AUTOINCREMENT primary key?

我使用下面的查询:

insert or replace into SectionDetails(Name,Month,Title,Url)values('Deepak',"August","None","www.dd619.com")

在这里列ID没有出现,因为它与主键 AUTOINCREMENT 属性。

推荐答案

简短的回答:不,它不需要

Short answer: no it does not.

插入或更换只有效果很好,当你还指定了主键。在一个安装了您所描述的自动增量,这可不行。

The "insert or replace" only works well when you also specify the primary key. With the autoincrement in a setup that you describe, this cannot work.

也许这样做的最快方法是创建您的使用情况下,自定义插入/更新方法。

Probably the quickest way to do that is by creating a custom insert/update method for your use case.

这篇关于请问sqlite的"插入或替换”包含自动增量主键的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆