我正在使用它作为资源来帮助我入门 - http://www.pantz.org/software/sqlite/sqlite_commands_and_general_usage.html
目前我正在使用内置的 SQLite 数据库创建一个 AIR 程序。在进行 SQL 查询方面,我可以被认为是一个完全的菜鸟。
表列类型
我有一个相当大的 excel 文件(14K 行),已导出到 CSV 文件。它有 65 列不同的数据类型(主要是整数、浮点数和短字符串,可能还有一些 bool 值)。我不知道导入的正确形式以保留列结构,也不知道为每个 db 列选择的最佳数据格式。我可以对此使用一些输入。
表创建工具
是否有可以读取 XLS 文件并基于列标题生成快速查询语句以减轻手动查询的痛苦的实用程序?我看到了这篇文章,但它似乎适用于预先存在的 CSV 文件并使用 python(我也是菜鸟)
提前感谢您的宝贵时间。
Ĵ
最佳答案
SQLite3 的列类型基本上可以归结为:
通常在 CSV 文件中,您会遇到字符串 (TEXT)、十进制数 (FLOAT) 和整数 (INT)。如果性能不重要,那么这些几乎就是您需要的仅有的三种列类型。 (
CHAR(80)
在磁盘上比 TEXT
小,但对于几千行来说,这不是什么大问题。)就将数据放入列而言,SQLite3 使用 类型强制 只要转换有意义,就将输入数据类型转换为列类型。因此,您所要做的就是指定正确的列类型,SQLite 将负责以正确的方式存储它。
例如号码
-1230.00
, 字符串 "-1230.00"
, 和字符串 "-1.23e3"
当存储在 FLOAT
中时,将全部强制为数字 1230柱子。请注意,如果 SQLite3 无法应用有意义的类型转换,它将只存储原始数据,而根本不尝试对其进行转换。 SQLite3 很乐意插入
"Hello World!"
变成 FLOAT
柱子。这通常是一件坏事。见SQLite3 documentation on column types and conversion对于 gem ,例如:
Type Affinity
In order to maximize compatibility between SQLite and other database engines, SQLite supports the concept of "type affinity" on columns. The type affinity of a column is the recommended type for data stored in that column. The important idea here is that the type is recommended, not required. Any column can still store any type of data. It is just that some columns, given the choice, will prefer to use one storage class over another. The preferred storage class for a column is called its "affinity".
关于excel - SQLite 3 CSV 导入表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9323423/