這是歷史版本頁面 — 看 SQLite (64-bit) 最新版本

SQLite 64位是什麼?輕量資料庫怎麼用

SQLite (64-bit) 軟體圖示 SQLite (64-bit) 3.41.0 (64-bit) 資料更新 2023-02-22 閱讀約 5 分鐘

寫個小工具或網站,需要把資料存下來,但想到要裝 MySQL 或 SQL Server 就頭痛——安裝程式好幾百 MB,設定服務、開 port、設帳號密碼,光前置作業就耗掉半天。你只是想讓程式把資料寫進檔案、之後能查得出來,不想為此養一台資料庫伺服器。

用 Excel 或 CSV 檔存資料,一開始很直覺,但資料一多、要跨表格比對或做條件篩選時,就開始卡。這類工具的切入點是「嵌入式資料庫」:不需要獨立伺服器,資料全部存在單一檔案裡,程式直接讀寫這個檔案,零設定、免安裝、離線可用。你要的只是把 SQL 查詢能力帶進你的應用程式,而不是管理一套資料庫系統。

01SQLite 64位能做什麼?

它是一個嵌入式資料庫引擎,不需要獨立伺服器,資料存在單一檔案中。你可以用 SQL 指令建立資料庫、建立表格、插入資料、查詢資料,支援大部分 SQL 標準,包括子查詢、JOIN 和觸發器。適合應用程式的本地儲存、行動裝置和嵌入式系統,例如桌面軟體的設定檔、遊戲存檔、分析工具的暫存資料。

02怎麼建立資料庫和表格?

下載 ZIP 檔解壓縮後,執行 sqlite3.exe,輸入 `sqlite3 database_name.db` 就會建立一個新的資料庫檔案。建立表格用 `CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);`,插入資料用 `INSERT INTO users (name) VALUES ('John Doe');`,查詢用 `SELECT * FROM users;`。整個過程不需要任何設定。

03支援哪些 SQL 功能?

支援大部分 SQL 標準,包括子查詢、JOIN、觸發器,也具備完整的 ACID 交易保證,確保資料完整性。資料庫最大可達 281TB,但實際效能會依硬體和查詢複雜度而異。官方文件相當完整,語法與其他關聯式資料庫類似,學過 SQL 的人可以很快上手。

04資料庫檔案可以多大?

官方說明指出最大可達 281TB,但效能會隨資料量增加而下降。對一般應用程式的本地儲存來說,幾 GB 到幾十 GB 都還算常見使用範圍。如果資料量極大且查詢複雜,效能衰減會很明顯,這套軟體不是為超大規模資料設計的。

05怎麼匯出資料?

在 sqlite3 命令列中,先輸入 `.mode csv` 設定輸出格式,再輸入 `.output file.csv` 指定輸出檔案,最後執行 `SELECT * FROM users;`,查詢結果就會寫入 CSV 檔案。要回到螢幕輸出時,輸入 `.output stdout` 即可。這是內建功能,不需要額外工具。

06需要安裝嗎?

不需要。下載 ZIP 檔後解壓縮到任意資料夾就能執行,也可以把資料夾加入系統的 PATH 環境變數,方便從任何位置呼叫 sqlite3.exe。整個過程完全離線運作,不需要網路連線,也沒有任何背景服務或常駐程式。

07免費嗎?

是,SQLite 採用公共領域授權,完全免費,任何人可以無限制使用,包含商業用途。不過,如果你需要加密功能,官方提供的 SQLite Encryption Extension(SEE)需要付費授權;另一個選擇是開源的 SQLCipher,但這不在官方預設支援範圍內,需要自行整合。

08多人同時使用適合嗎?

不適合。SQLite 設計用於本地儲存,雖然支援多個連線,但不是為高流量並發環境最佳化。多人同時寫入時可能遇到鎖定問題,官方說明也明確指出它不適合高並發環境。如果你的應用需要多人同時讀寫,應該考慮 MySQL 或 PostgreSQL 這類完整 RDBMS。

09有圖形介面嗎?

SQLite 本身沒有圖形介面,只有命令列工具。官方說明提到可以搭配第三方 GUI 工具,例如 DB Browser for SQLite 或 SQLiteStudio,這些工具提供圖形化的資料庫結構檢視,方便瀏覽表格、執行查詢、匯入匯出資料。如果你習慣視覺化操作,需要另外下載這些工具。

10需要使用者管理嗎?

不需要,SQLite 沒有內建認證或使用者管理功能。資料庫就是一個檔案,任何能存取該檔案的人都能讀寫全部內容。如果你的應用需要區分使用者權限,必須在應用層自行實作,或改用有內建帳號管理的資料庫系統。這對單機應用不是問題,但對多人共享的環境就是限制。

11資料量很大適合嗎?

不適合。官方說明指出,資料量很大時效能會下降,而且不適合大規模多使用者應用。它擅長的是單一使用者或嵌入式場景,例如應用程式本地儲存、行動裝置、小型工具。如果你的資料預期會成長到數十 GB 以上,或需要多人同時查詢,應該評估其他資料庫方案。

下載與官方連結

前往官方網站 下載 SQLite (64-bit)

sqlite-dll-win64-x64-3410000.zip · 連結指向軟體原廠

版本紀錄

再看 5 筆

看完整版本清單

這一版改了什麼

What's new in this version:

Query planner improvements:
- Make use of indexed expressions within an aggregate query that includes a GROUP BY clause
- The query planner has improved awareness of when an index is a covering index and adjusts predicted runtimes accordingly
- The query planner is more aggressive about using co-routines rather than materializing subqueries and views
- Queries against the built-in table-valued functions json_tree() and json_each() will now usually treat "ORDER BY rowid" as a no-op
- Enhance the ability of the query planner to use indexed expressions even if the expression has been modified by the constant-propagation optimization. (See forum thread 0a539c7.)
- Add the built-in unhex() SQL function.
- Add the base64 and base85 application-defined functions as an extension and include that extension in the CLI
- Add the sqlite3_stmt_scanstatus_v2() interface. (This interface is only available if SQLite is compiled using SQLITE_ENABLE_STMT_SCANSTATUS.)
- In-memory databases created using sqlite3_deserialize() now report their filename as an empty string, not as 'x'

Changes to the CLI:
- Add the new base64() and base85() SQL functions
- Enhanced EXPLAIN QUERY PLAN output using the new sqlite3_stmt_scanstatus_v2() interface when compiled using SQLITE_ENABLE_STMT_SCANSTATUS
- The ".scanstats est" command provides query planner estimates in profiles
- The continuation prompt indicates if the input is currently inside of a string literal, identifier literal, comment, trigger definition, etc
- Enhance the --safe command-line option to disallow dangerous SQL functions
- The double-quoted string misfeature is now disabled by default for CLI builds. Legacy use cases can reenable the misfeature at run-time using the ".dbconfig dqs_dml on" and ".dbconfig dqs_ddl on" commands.
- Enhance the PRAGMA integrity_check command so that it detects when text strings in a table are equivalent to but not byte-for-byte identical to the same strings in the index.
- Enhance the carray table-valued function so that it is able to bind an array of BLOB objects
- Added the sqlite3_is_interrupted() interface
- Long-running calls to sqlite3_prepare() and similar now invoke the progress handler callback and react to sqlite3_interrupt()
- The sqlite3_vtab_in_first() and sqlite3_vtab_in_next() functions are enhanced so that they reliably detect if they are invoked on a parameter that was not selected for multi-value IN processing using sqlite3_vtab_in(). They return SQLITE_ERROR instead of SQLITE_MISUSE in this case.
- The parser now ignores excess parentheses around a subquery on the right-hand side of an IN operator, so that SQLite now works the same as PostgreSQL in this regard. Formerly, SQLite treated the subquery as an expression with an implied "LIMIT 1".
- Added the SQLITE_FCNTL_RESET_CACHE option to the sqlite3_file_control() API

Makefile improvements:
- The new makefile target "sqlite3r.c" builds an amalgamation that includes the recovery extension
- New makefile targets "devtest" and "releasetest" for running a quick developmental test prior to doing a check-in and for doing a full release test, respectively
- Miscellaneous performance enhancements