SQLite:自动增量主键问题 [英] SQLite: autoincrement primary key questions
本文介绍了SQLite:自动增量主键问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 SQLite 查询:
I have the following SQLite query:
CREATE TABLE Logs ( Id integer IDENTITY (1, 1) not null CONSTRAINT PKLogId PRIMARY KEY, ...
IDENTITY (1, 1)
-> 这是什么意思?PKLogId
这是什么?这似乎没有在任何地方定义- 我希望
Id
成为带有autoincrement
的整数主键
.我希望能够插入到这个Logs
表中,在我的查询中省略Id
列.我希望Id
自动添加和递增.这可能吗?我该怎么做?
IDENTITY (1, 1)
-> What does this mean?PKLogId
what is this? This doesn't seem to be defined anywhere- I want
Id
to beinteger primary key
withautoincrement
. I would like to be able to insert into thisLogs
table omittingId
column in my query. I wantId
to be automatically added and incremented. Is this possible? How can I do this?
当我尝试在没有 Id
的情况下插入时,我得到:
At the moment when I try to insert without Id
I get:
Error while executing query: Logs.Id may not be NULL
推荐答案
根据示例的语法,我不确定您是否真的在使用 SQLite.
I'm not sure whether you're actually using SQLite according to the syntax of your example.
如果您是,您可能对 SQLite 常见问题 #1:如何创建 AUTOINCREMENT 感兴趣字段?:
If you are, you may be interested in SQLite FAQ #1: How do I create an AUTOINCREMENT field?:
简短回答:声明为 INTEGER PRIMARY KEY 的列将自增.
Short answer: A column declared INTEGER PRIMARY KEY will autoincrement.
这篇关于SQLite:自动增量主键问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文