2012-11-29 23 views
1

我不熟悉数据库。现在我即将学习sqlite。我下载了sqlite shell 3.7.14.1。我试图创建一个数据库长谷歌搜索了很长一段时间。但无法找到答案。
在壳我给了命令sqlite3 test.db然后它显示...>然后我退出与命令.exit但我看不到数据库被创建。请有人可以帮我解决这个问题。sqlite database fundermentles

enter image description here enter image description here

+0

你怎么知道没有创建数据库?你有没有尝试过创建任何表格? http://www.sqlite.org/sqlite.html –

+0

是的,我刚刚创建了一个表'sqlite>创建表mytable(id整数主键,值文本)'也。在工作目录中没有创建名为test.db –

+0

@MattBall的文件我想知道创建的.db文件在哪里。它不在工作目录 –

回答

1

命令:

sqlite3 test.db 

将创建该文件在数据库中称为test.db。您可以继续创建表格,并且可以在该数据库中查找并查询数据。

试试这个:

sqlite3 test.db "create table test_table (someid INTEGER PRIMARY KEY, somedata TEXT);" 
sqlite3 test.db "insert into test_table values (1, 'Some Text');" 

然后在Windows

enter image description here

+0

这个文件是在哪里创建的。在工作目录中没有创建 –

+0

只要您在其中放入了一些数据,就会创建一个表定义,文件将被创建。如果您刚刚启动客户端并立即退出,则不会写入任何文件。该文件将在当前目录中创建。 – Mithrandir

+0

是的,我也创建了一个表,并添加了一些数据。但是当我给命令'.exit'时显示'...>'。它dosnt退出或创建一个。db文件,可能是什么原因 –

1

确定样本 “会话” 尚未创建

sqlite3 test.db "select * from test_table;" 

这里?

尝试sqllite命令.databases确保

+0

.database命令不会返回,除非'...>' –

1

...> 

是从SQLite的续行提示。改为按照下面的步骤。

$ sqlite3 test.db 
SQLite version 3.7.9 2011-11-01 00:52:41 
Enter ".help" for instructions 
Enter SQL statements terminated with a ";" 
sqlite> create table test (n integer primary key); 
sqlite> .quit 

$ ls test.db 
test.db 

您也可以将SQL字符串管道化到SQLite中。

$ echo "create table test_2 (n integer primary key);" | sqlite3 test.db 

你可以看看这样的表格。

$ sqlite3 test.db 
SQLite version 3.7.9 2011-11-01 00:52:41 
Enter ".help" for instructions 
Enter SQL statements terminated with a ";" 
sqlite> .tables 
test test_2 

或者提供SQL字符串作为sqlite3可执行文件的参数。

$ sqlite3 test.db "create table test3 (n integer primary key);" 
+0

我编辑了我的问题,并在下面添加了屏幕截图。它只显示'...>'没有任何反应。我做错了什么 –

+1

我的例子中的“$”是我的shell提示符,而不是你键入SQLite的东西。完全脱离sqlite,并从shell的提示符开始。然后从我的第一个例子开始。注意你的提示。 –