问题描述
Sqlite 有点令人沮丧.每次运行命令时,我都无法使用上下左右箭头来检索以前键入的命令.有什么办法可以启用此功能吗?
Sqlite is kinda frustrating. Each time I run a command, I'm not able to use the up down left right arrows to retrieve my previously typed commands. Is there any way to enable this?
另一个问题:我有下表
CREATE TABLE resource (
resourceID INTEGER PRIMARY KEY AUTOINCREMENT,
resourceType STRING,
userID INTEGER DEFAULT -1
);
我插入如下:
insert into resource values(null, "razor");
但它不允许我这样做,因为我只插入了 2 列并且没有为 userID 列指定任何内容.但我认为 DEFAULT 的重点是如果没有插入任何内容,则将值默认为 -1.我在这里遗漏了什么吗?
but its not allowing me to do so because I have only inserted into 2 columns and not specified anything for the userID column. But I thought the point of DEFAULT was to default the values to -1 if nothing was inserted. Am I missing something here?
推荐答案
以下是两个问题的两个答案:
Here are two answers for two questions:
我发现使用 sqlite3 命令行客户端时,我的箭头键可以毫无问题地工作.
I find that using the sqlite3 command line client my arrow keys work without trouble.
您的 INSERT 语句中有两个错误:
You have two errors in your INSERT statement:
您不应为 AUTOINCREMENT 列提供值.
You should not supply a value for the AUTOINCREMENT column.
您应该列出列和映射值的顺序.当您没有与列相同数量的值时,这是必需的,但即使这样做也是一种很好的做法,因为以后对表结构的更改可能会更改列的顺序或数量.
You should list the columns and the order in which to map the values. This is required when you do not have the same amount of values as columns, but it's good practice even when you do, because later changes to the table's structure may change the order or number of columns.
此外,单引号在 SQL 数据库中更为标准.SQLite 会接受双引号,而其他一些程序则不会.
Also, single quotes are more standard in SQL databases. SQLite will accept the double quotes, some other programs won't.
INSERT INTO Resource (ResourceType) VALUES ('razor')
INSERT INTO Resource (ResourceType) VALUES ('razor')
这篇关于Sqlite 使用命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!