SQLite
是一个软件库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。SQLite是一个增长最快的数据库引擎,这是在普及方面的增长,与它的尺寸大小无关。SQLite 源代码不受版权限制。
1. Install
请访问 SQLite 下载页面,从源代码区下载 sqlite-autoconf-*.tar.gz。
$ tar xvzf sqlite-autoconf-3071502.tar.gz
$ cd sqlite-autoconf-3071502
$ ./configure --prefix=/usr/local
$ make
$ make install
2. Example (Sql语句)
2.1 创建数据库
$ sqlite3 DatabaseName.db
2.2 创建表
CREATE TABLE database_name.table_name(
column1 datatype PRIMARY KEY(one or more columns),
column2 datatype,
column3 datatype,
.....
columnN datatype,
);
eg:
sqlite> CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
2.3 增
INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]
VALUES (value1, value2, value3,...valueN);
eg:
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Paul', 32, 'California', 20000.00 );
2.4 删
DELETE FROM table_name
WHERE [condition];
eg:
sqlite> DELETE FROM COMPANY WHERE ID = 7;
2.5 改
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
eg:
sqlite> UPDATE COMPANY SET ADDRESS = 'Texas' WHERE ID = 6;
2.6 查
SELECT column1, column2, columnN FROM table_name;
eg:
sqlite> SELECT ID, NAME, SALARY FROM COMPANY;
3. 点命令
3.1 命令行进入sqlite,可执行点命令。
3.2
.help
查看帮助
3.3
.databases
查看数据库
3.4
.header on
查看显示表头
3.5
.mode column
查看以列形式显示表