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。

相关文章
相关标签/搜索