- SQLite 教程
- SQLite 简介
- SQLite 安装
- SQLite 命令
- SQLite 语法
- SQLite 数据类型
- SQLite 创建数据库
- SQLite 附加数据库
- SQLite 分离数据库
- SQLite 创建表
- SQLite 删除表
- SQLite Insert 语句
- SQLite Select 语句
- SQLite 运算符
- SQLite 表达式
- SQLite Where 子句
- SQLite AND/OR 运算符
- SQLite Update 语句
- SQLite Delete 语句
- SQLite Like 子句
- SQLite Glob 子句
- SQLite Limit 子句
- SQLite Order By
- SQLite Group By
- SQLite Having 子句
- SQLite Distinct 关键字
-
SQLite 高级教程
- SQLite PRAGMA
- SQLite 约束
- SQLite Joins
- SQLite Unions 子句
- SQLite NULL 值
- SQLite 别名
- SQLite 触发器(Trigger)
- SQLite 索引(Index)
- SQLite Indexed By
- SQLite Alter 命令
- SQLite Truncate Table
- SQLite 视图(View)
- SQLite 事务(Transaction)
- SQLite 子查询
- SQLite Autoincrement(自动递增)
- SQLite 注入
- SQLite Explain(解释)
- SQLite Vacuum
- SQLite 日期 & 时间
- SQLite 常用函数
- SQLite 接入
SQLite 创建数据库
SQLite 的 sqlite3 命令被用来创建新的 SQLite 数据库。您不需要任何特殊的权限即可创建一个数据。
语法
sqlite3 命令的基本语法如下:
$sqlite3 DatabaseName.db
通常情况下,数据库名称在 RDBMS 内应该是唯一的。
实例
如果您想创建一个新的数据库 <testDB.db>,SQLITE3 语句如下所示:
$sqlite3 testDB.db SQLite version 3.7.15.2 2013-01-09 11:53:05 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite>
上面的命令将在当前目录下创建一个文件 testDB.db。该文件将被 SQLite 引擎用作数据库。如果您已经注意到 sqlite3 命令在成功创建数据库文件之后,将提供一个 sqlite> 提示符。
一旦数据库被创建,您就可以使用 SQLite 的 .databases 命令来检查它是否在数据库列表中,如下所示:
sqlite>.databases seq name file --- --------------- ---------------------- 0 main /home/sqlite/testDB.db
您可以使用 SQLite .quit 命令退出 sqlite 提示符,如下所示:
sqlite>.quit $
.dump 命令
您可以在命令提示符中使用 SQLite .dump 点命令来导出完整的数据库在一个文本文件中,如下所示:
$sqlite3 testDB.db .dump > testDB.sql
上面的命令将转换整个 testDB.db 数据库的内容到 SQLite 的语句中,并将其转储到 ASCII 文本文件 testDB.sql 中。您可以通过简单的方式从生成的 testDB.sql 恢复,如下所示:
$sqlite3 testDB.db < testDB.sql
此时的数据库是空的,一旦数据库中有表和数据,您可以尝试上述两个程序。现在,让我们继续学习下一章。
上一篇:SQLite 数据类型
下一篇:SQLite 附加数据库
扫描二维码
程序员编程王