- SQLite 教程
- 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 - 連線
- SQLite - UNIONS 子句
- SQLite - NULL 值
- SQLite - 別名語法
- SQLite - 觸發器
- SQLite - 索引
- SQLite - INDEXED By 子句
- SQLite - ALTER 命令
- SQLite - TRUNCATE 命令
- SQLite - 檢視
- SQLite - 事務
- SQLite - 子查詢
- SQLite - AUTOINCREMENT
- SQLite - 注入
- SQLite - EXPLAIN
- SQLite - VACUUM
- SQLite - 日期和時間
- SQLite - 有用函式
- SQLite 有用資源
- 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 命令
您可以使用.dump點命令將完整資料庫匯出到文字檔案,在命令提示符下使用以下 SQLite 命令。
$sqlite3 testDB.db .dump > testDB.sql
上述命令將把testDB.db資料庫的全部內容轉換為 SQLite 語句,並將其轉儲到 ASCII 文字檔案testDB.sql中。您可以以以下簡單方式從生成的 testDB.sql 中執行恢復:−
$sqlite3 testDB.db < testDB.sql
目前您的資料庫為空,因此在資料庫中有一些表和資料後,您可以嘗試上述兩個過程。現在,讓我們繼續下一章。
廣告