SQLite 多个自动增量列?
我尝试使用以下 SQL 来创建表和一些列。作为其中的一部分,我希望其中两列自动递增一个整数。当我尝试使用下面的代码时,它给了我一个错误。
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 中删除关键字“AUTOINCRMENT”时,它工作正常。
是否可以有两个自动递增列?如果没有,有没有办法让一列在插入时自动从另一列(自动递增)中获取值?
谢谢
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')
)
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?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不能有两个自动增量字段。您应该使用单个自动增量字段。鉴于每行的两个字段始终具有相同的值,无论如何都没有理由必须使用这些字段。
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.
我最初需要两个具有相同值的字段,但“位置”字段将在稍后更新,因此我确实需要两个单独的值。有没有办法让“position”字段在插入时自动获取“rowID”中的值
http://www.sqlite.org/lang_createtrigger.html
尝试使用插入后触发器,将 colB = 设置为 colA 的值。 ColA 是自动递增值。
I need two fields with the same values initially, but the "position" field will be updated at a later time, so I do need two separate values. Is there a way I can have the "position" field automatically take the value from "rowID" as its being inserted
http://www.sqlite.org/lang_createtrigger.html
Try using an after-insert trigger, setting colB = to colA's value. ColA is the auto-incremented value.