如何使用 DB Browser SQLite 在列中添加批量值
How to add bulk values in column using DB Browser SQLite
我有一个包含两列的 table。一列 "rewords" 包含 12186 个单词。另一个名为 "ID" 的列是我新创建的列,因此它是空的。我想在 rewords 列中添加数字。从 1、2、3 到 12186 的数字。我尝试使用主键而不是空操作,但它扰乱了顺序,它的序列变得像 1、2、6、10、7、8、19 一样 unpredictable。 ...
如果我在字段中手动输入1,2,3,那将是太费时费力了。以下是我想要的截图。我希望我可以在 ID 列的字段中输入 1 到 12186。
我还在查询选项卡中尝试了以下功能,但它不起作用并给出错误 "near "for": syntax error: for"
for(int i = 1; i<=12186; i++){
UPDATE tbl SET ID = i WHERE index = i;
}
您不需要循环,您可以通过单个查询完成此操作
UPDATE tbl
SET ID = index
WHERE index <= 12186;
否则如果你没有列索引..你需要在你的id列中有一个自动增量值..你应该
你可以用 SQLite Expert Personal 4 来做:
1) Select the table and then go to "Design" tab > "Columns" tab.
2) Click select the ID column name, and type INTEGER and Not Null > Ok.
3) Go to "Primary Key" tab in "Desgin tab".
Click "Add" and select the column ID. Check the "Autoincrement" box.
4) Click "Apply" on the right bottom part of the window.
我有一个包含两列的 table。一列 "rewords" 包含 12186 个单词。另一个名为 "ID" 的列是我新创建的列,因此它是空的。我想在 rewords 列中添加数字。从 1、2、3 到 12186 的数字。我尝试使用主键而不是空操作,但它扰乱了顺序,它的序列变得像 1、2、6、10、7、8、19 一样 unpredictable。 ... 如果我在字段中手动输入1,2,3,那将是太费时费力了。以下是我想要的截图。我希望我可以在 ID 列的字段中输入 1 到 12186。
我还在查询选项卡中尝试了以下功能,但它不起作用并给出错误 "near "for": syntax error: for"
for(int i = 1; i<=12186; i++){
UPDATE tbl SET ID = i WHERE index = i;
}
您不需要循环,您可以通过单个查询完成此操作
UPDATE tbl
SET ID = index
WHERE index <= 12186;
否则如果你没有列索引..你需要在你的id列中有一个自动增量值..你应该
你可以用 SQLite Expert Personal 4 来做:
1) Select the table and then go to "Design" tab > "Columns" tab.
2) Click select the ID column name, and type INTEGER and Not Null > Ok.
3) Go to "Primary Key" tab in "Desgin tab".
Click "Add" and select the column ID. Check the "Autoincrement" box.
4) Click "Apply" on the right bottom part of the window.