如何创建新的 SQLite 数据库?

发布于 2024-08-28 12:15:14 字数 356 浏览 5 评论 0原文

我正在 Mac OS X 上工作, 我想创建一个新的 SQLite 数据库,并且 我使用 http://www.sqlite.org/quickstart.html 作为参考。

我正在输入:sqlite3 test.db 并得到答复:

SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

为什么会发生这种情况?

I am working on Mac OS X,
I want to create a new SQLite DB, and
I am using http://www.sqlite.org/quickstart.html as a reference.

I am entering: sqlite3 test.db
and getting the response:

SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

Why is this happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

嗫嚅 2024-09-04 12:15:14

它起作用了。退出并测试 - 数据库已创建。

您现在处于 SQLite shell 中,并且已准备好接收诸如 CREATE TABLE...INSERT INTO... 等命令。

如果您不想这样做使用交互式 shell,您可以直接从命令行构建模式:

sqlite3 test.db "CREATE TABLE ..."

或者只是创建一个没有模式的空数据库:

sqlite3 test.db ""

但这与创建一个空文件相同:

touch test.db

It worked. Quit out and test - the database has been created.

You are now in the SQLite shell, and it is ready to receive commands like CREATE TABLE..., INSERT INTO..., etc.

If you would prefer not to use the interactive shell, you can build your schema straight from the command line:

sqlite3 test.db "CREATE TABLE ..."

Or just create an empty database with no schema:

sqlite3 test.db ""

But that's the same as just creating an empty file, anyway:

touch test.db
水晶透心 2024-09-04 12:15:14

因为那是管理 shell 提示符。 shell 创建了 test.db,现在正在等待您对其执行某些操作,因此您会看到 sqlite> 提示符。

此时您可能想要创建表...

Because that is the administrative shell prompt. The shell created test.db and is now waiting for you to do something with it thus the sqlite> prompt you see.

You may want to create table ... at this point.

几度春秋 2024-09-04 12:15:14

所以没关系。系统会提示您输入命令。创建表,插入,选择。玩得开心!

so it is fine. you are prompted to enter commands. create table, insert, select. have fun!

吾家有女初长成 2024-09-04 12:15:14

您将进入 SQLite 提示符(您可以在其中创建表、添加数据等)。根据您发布的内容,没有任何异常。

You're being taken to the SQLite prompt (where you can create tables, add data, etc.). Nothing appears out of the ordinary based on what you've posted.

疯到世界奔溃 2024-09-04 12:15:14

例如,使用新数据库名称 mydb.sqlite3 运行 SQLite3 并创建如下所示的表 person 可以创建新数据库 mydb.sqlite3

sqlite3 mydb.sqlite3
...
sqlite> CREATE TABLE person(id integer, name text);

并且,您可以通过一行命令来完成上述操作,如下所示:

sqlite3 mydb.sqlite3 'CREATE TABLE person(id integer, name text)'

或者:

sqlite3 mydb.sqlite3 "CREATE TABLE person(id integer, name text)"

请注意,仅使用如下所示的新数据库名称 mydb.sqlite3 运行 SQLite3 无法创建新数据库mydb.sqlite3

sqlite3 mydb.sqlite3

此外,您可以使用''""创建空数据库mydb.sqlite3,如图所示如下:

sqlite3 mydb.sqlite3 ''

或:

sqlite3 mydb.sqlite3 ""

For example, running SQLite3 with the new database name mydb.sqlite3 and creating the table person as shown below can create the new database mydb.sqlite3:

sqlite3 mydb.sqlite3
...
sqlite> CREATE TABLE person(id integer, name text);

And, you can do the above with one line of command as shown below:

sqlite3 mydb.sqlite3 'CREATE TABLE person(id integer, name text)'

Or:

sqlite3 mydb.sqlite3 "CREATE TABLE person(id integer, name text)"

Be careful, only running SQLite3 with the new database name mydb.sqlite3 as shown below cannot create the new database mydb.sqlite3:

sqlite3 mydb.sqlite3

In addition, you can create the empty database mydb.sqlite3 with '' or "" as shown below:

sqlite3 mydb.sqlite3 ''

Or:

sqlite3 mydb.sqlite3 ""
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文