SQLite

Table of Contents

1. SQLite 简介

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

参考:
https://www.sqlite.org/
http://www.tutorialspoint.com/sqlite/index.htm

2. 命令行接口

用命令 sqlite3 filename.db 可以打开数据库文件 filename.db(如果 filename.db 不存在,则会创建它)。用命令 .quit 或者 Ctrl+D 可以退出交互终端。如:

$ sqlite3 ex1.db
SQLite version 3.8.5 2014-08-15 22:37:57
Enter ".help" for usage hints.
sqlite> create table tbl1(one varchar(10), two smallint);
sqlite> insert into tbl1 values('hello!',10);
sqlite> insert into tbl1 values('goodbye', 20);
sqlite> select * from tbl1;
hello!|10
goodbye|20
sqlite> .quit

要查看数据库中存在哪些表,可以使用命令 .tables 。要查看表的定义可以使用命令 .schema 。如:

sqlite> .tables
tbl1
tbl2
sqlite> .schema
create table tbl1(one varchar(10), two smallint)
CREATE TABLE tbl2 (
  f1 varchar(30) primary key,
  f2 text,
  f3 real
)
sqlite> .schema tbl2
CREATE TABLE tbl2 (
  f1 varchar(30) primary key,
  f2 text,
  f3 real
)

参考:
Command Line Shell For SQLite: https://www.sqlite.org/cli.html

Author: cig01

Created: <2014-12-13 Sat>

Last updated: <2016-03-27 Sun>

Creator: Emacs 27.1 (Org mode 9.4)