sql - 如何使用 DB Browser SQLite 在列中添加批量值
问题描述
我有一个包含两列的表。一列“rewords”包含 12186 个单词。另一个名为“ID”的列是我新创建的列,所以它是空的。我想在 rewords 列中添加数字。从 1、2、3 到 12186 的数字。我尝试使用主键而不是 null 操作,但它扰乱了顺序,并且它的顺序变得不可预测,如 1、2、6、10、7、8、19 .... 如果我手动在字段中输入 1,2,3,那会太费时费力。以下是我想要的截图。我希望我可以在 ID 列的字段中输入 1 到 12186。
我还在查询选项卡中尝试了以下功能,但它不起作用并给出“接近“for”的错误:语法错误: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.
推荐阅读
- php - 带有laravel的网址中的问号
- imagemagick - 使用 imagemagick 在图像前添加文本
- c++ - C++ promise.set_value 在 linux 下因未知错误而失败
- ios - Safari IOS 在屏幕顶部有可点击的元素对 iPhone 上的横向效果不太好
- c++ - 半精度数的数学库
- django - Django - 访问外键值以保存到字典
- tensorflow - TensorFlow 的 DirectoryIterator 是如何工作的?
- javascript - 使用 Antd 表列和列组的替代方法
- java - 如何获得某个符号之前的第一个单词
- powershell - 需要从文本文件中提取内容并增加文件名