SQLite的源代码是C,其源代码完全开放。SQLite第一个Alpha版本诞生于2000年5月。 他是一个轻量级的嵌入式数据库。
SQLite有以下特性:
零配置一无需安装和管理配置;
储存在单一磁盘文件中的一个完整的数据库;
数据库文件可以在不同字节顺序的机器间自由共享;
支持数据库大小至2TB(1024G = 1TB);足够小,全部源码大致3万行c代码,250KB;
比目前流行的大多数数据库对数据的操作要快;
操作数据库
1. sqlite3系统命令(类似Windows系统命令,开机关机等,都是以.开头的)
都是以 '.' 开头的
a. .help 查看所有支持的命令
b. .quit 退出
c. .tables 查看有哪些表
d. .schema stu2 查看表结构
SQL命令
1.创建一个表
create table stu(id int,name char,score float);
create table stu1(id int primary key,name char,score float);
注:把id字段设置为主键(在表中唯一);
字符串 :char string text
小数: float real
2.删除一个表
drop table <table_name>;
3.向表里插入数据
insert into <table_name> values(value1,value2,...);
例:insert into stu values(1,"xiaoming",99.9);//只插入部分字段 id name score
4.查找数据
查询表中所有记录
select * from <table_name>;
按指定条件查询表中记录
select * from <table_name> where <expression>
例:select * from stu where id=2;
select * from stu where id=2 and name='lisa';
select * from stu limit N;//只查询前N条数据
select * from stu order by id desc;//按id从大到小进行排序
5.修改数据
update <table_name> set <f1=value1> <f2=value2>... where <expression>
例:update stu set id=10 where id=1;
6.增加字段
alter table <table_name> add column <field> <type> default ...;
例:alter table stu add column class int default 1;//表示添加了一列class,默认值为1