SQLite:自动增量主键问题 [英] SQLite: autoincrement primary key questions

查看:35
本文介绍了SQLite:自动增量主键问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 SQLite 查询:

I have the following SQLite query:

CREATE TABLE Logs ( Id integer IDENTITY (1, 1) not null CONSTRAINT PKLogId PRIMARY KEY, ...

  1. IDENTITY (1, 1) -> 这是什么意思?
  2. PKLogId 这是什么?这似乎没有在任何地方定义
  3. 我希望 Id 成为带有 autoincrement整数主键.我希望能够插入到这个 Logs 表中,在我的查询中省略 Id 列.我希望 Id 自动添加和递增.这可能吗?我该怎么做?
  1. IDENTITY (1, 1) -> What does this mean?
  2. PKLogId what is this? This doesn't seem to be defined anywhere
  3. I want Id to be integer primary key with autoincrement. I would like to be able to insert into this Logs table omitting Id column in my query. I want Id 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屋!

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