如何在具有唯一 ID 的 SQLite 中插入重复行? [英] How to insert duplicate rows in SQLite with a unique ID?

查看:34
本文介绍了如何在具有唯一 ID 的 SQLite 中插入重复行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来很简单:我想在 SQLite 表中复制一行:

This seems simple enough: I want to duplicate a row in a SQLite table:

INSERT INTO table SELECT * FROM table WHERE rowId=5;

如果没有明确的唯一列声明,该语句将起作用,但表的第一列声明为 rowID INTEGER NOT NULL PRIMARY KEY.有没有什么方法可以创建一个像上面那样的简单语句,在不知道表的架构的情况下(第一列除外)?

If there were no explicit unique column declarations, the statement would work, but the table's first column is declared rowID INTEGER NOT NULL PRIMARY KEY. Is there any way to create a simple statement like the one above that works without knowing the schema of the table (aside from the first column)?

推荐答案

好吧,由于我无法按照我想要的方式执行此操作,因此我求助于使用隐式行 id,该行 id 与 rowId 具有相同的名称我明确定义的列,所以现在我可以使用我在问题中的查询,它将使用新的 rowId 插入所有数据.为了让程序的其余部分正常工作,我只是将 SELECT * FROM table 更改为 SELECT rowId,* FROM table,一切都很好.

Well, since I was unable to do this the way I wanted, I resorted to using the implicit row id, which handily enough has the same name as the rowId column I defined explicitly, so now I can use the query I had in the question, and it will insert all the data with a new rowId. To keep the rest of the program working, I just changed SELECT * FROM table to SELECT rowId,* FROM table and everything's fine.

这篇关于如何在具有唯一 ID 的 SQLite 中插入重复行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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