一、基本数据库操作
1、启动命令行,通过如下命令打开Shell模式的CLP:
splite3 test.db
2、shell中创建表
sqlite> create table test(id interger primary key,value text);
3、向表中插入几行
sqlite> insert into test (id,value) values(1,'djsh')
4、返回插入内容
sqlite> .mode column
sqlite> .headers on
sqlite> select* from test
5、显示内容如图所示:
id value
------ -------
1 ennie
2 meenie
3 miny
4 mo
6、使用SQL函数last_insert_rowid()获得最后插入的自动增量值
sqlite> select last_insert_rowid();
7、返回表
sqlite> .indices test
8、为表添加索引和视图
sqlite> create index test_idx on test (value);
sqlite> create view schema as select * from sqlite_master;
9、显示表的索引
sqlite> .indices test
10、显示表的视图
sqlite> .schema test
sqlite> .schema
11、查询当前数据库的sqlite_master表
sqlite> select tupe,name,tbl_name,sql from sqlite_master order by type
12、打开数据库
sqlite3 foods.db
13、更改数据表
alter table contacts add column email text not null default ''collate nocase;
14、查看表定义
sqlite> .schema contacts
二、数据库基本概念
1、test.db对象的完整清单包括:一个表、一个索引和一个视图
2、SQL 关键字 select、update、insert、create、drop、begin
3、SQL组成部分:
1)数据库定义语言(DDL)—用来创建和销毁数据库对象的部分
2)数据库操作语言(DML)—咋数据库对象上执行操作的功能部分
3)Sqlite 中有5中本地类型:integer/real/text/blobl/null