SQLite multiple Autoincrement Columns?(SQLite多个自动增量列?)
问题描述
我尝试使用以下 SQL 来创建表和一些列.作为其中的一部分,我希望其中两列自动递增一个整数.当我尝试使用下面的代码时,它给了我一个错误.
I have the below SQL I am trying to use to create a table and some columns. As part of it, I want two of the columns to autoincrement an integer. When I try using the below code it gives me an error.
CREATE TABLE IF NOT EXISTS 'tasks' (
'rowID' INTEGER,
'gID' INTEGER,
'task' TEXT,
'status' TEXT,
'position' INTEGER,
'updated' INTEGER,
'inlist' TEXT,
'deleted' TEXT,
PRIMARY KEY AUTOINCREMENT ('rowID','position')
)
当我从 SQL 中删除关键字AUTOINCREMENT"时,它可以正常工作.
When I remove the keyword "AUTOINCREMENT" from the SQL it works fine.
是否可以有两个自增列?如果没有,有没有一种方法可以让一列在插入时自动从另一列(自动递增)中获取值?
Is it possible to have two autoincrementing columns? If not, is there a way I can have one column automatically take the value from the other (auto-incrementing) column as its being inserted?
谢谢
推荐答案
你不能有两个自增字段.您应该使用单个自动增量字段.鉴于这两个字段对于每一行总是具有相同的值,因此没有理由必须使用这些字段.
You can't have two autoincrement fields. You should use a single autoincrement field. Given that both fields would always have the same value for every row, there's no reason to have to such fields anyway.
这篇关于SQLite多个自动增量列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQLite多个自动增量列?


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01