SQLite筆記(一)

簡介

官網https://www.sqlite.orghtml

SQLite is an in-process library that implements a self-containedserverlesszero-configurationtransactional SQL database engine. sql

SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. 數據庫

所以,SQLite的安裝很簡單,最新的Linux和Mac上都自帶sqlite3(早期版本能夠下載源碼make),windows上下載sqlite文件便可(綠色)。若是下載了Android SDK,在platform-tools目錄中,你會找到sqlite3。windows

使用

(Windows)cd到sqlite3目錄,輸入sqlite3後,便可執行SQLite命令——包括Create、drop等命令。app

Linux、Mac終端下,直接輸入sqlite3,而後是命令。less

命令

.help: 顯示命令列表ide

.quit: 退出工具

.open 文件名:打開數據庫 —— 還能夠直接sqlite3 文件名打開數據庫。ui

.tables: 列出全部的數據表spa

注:命令輸入;以後纔會執行。

SQL語句

https://www.sqlite.org/lang.html

數據類型: https://www.sqlite.org/datatype3.html

Windows可視化管理工具

SQLiteSpy,SQLiteStudio,SQLiteExpert

自增加字段

https://www.sqlite.org/autoinc.html

  1. The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed.

  2. In SQLite, a column with type INTEGER PRIMARY KEY is an alias for the ROWID (except in WITHOUT ROWID tables) which is always a 64-bit signed integer.

  3. On an INSERT, if the ROWID or INTEGER PRIMARY KEY column is not explicitly given a value, then it will be filled automatically with an unused integer, usually one more than the largest ROWID currently in use. This is true regardless of whether or not the AUTOINCREMENT keyword is used.

  4. If the AUTOINCREMENT keyword appears after INTEGER PRIMARY KEY, that changes the automatic ROWID assignment algorithm to prevent the reuse of ROWIDs over the lifetime of the database. In other words, the purpose of AUTOINCREMENT is to prevent the reuse of ROWIDs from previously deleted rows.

建立without rowid的表:https://www.sqlite.org/withoutrowid.html 

有三種創建自增加的字段:rawid,INTEGER PRIMARY KEY和INTEGER PRIMARY KEY AUTOINCREMENT。

相關文章
相關標籤/搜索