【1】 sqlite3的安装:
2.在线安装:sudo apt-get install sqlite3
3.如果在编程的时候,找不到sqlite3.h文件,则安装库文件: sudo apt-get install libsqlite3-dev
【2】 sqlite3的基本命令:
1.系统命令:
以‘.’(点)开头的命令
.help 帮助
.quit 退出
.exit 退出
.schema 查看表的结构图
.databases 查看打开的数据库
.table 查看表
2.sql命令:
不以‘.’(点)开头,但是需要以‘;’(分号)结尾;
1)创建一张数据的表
create table student(no Integer,name char,score float);
create table student(no Integer primary key,name char,score float); //将no作为主键,不能插入相同主键的数据。
数据类型:
Integer 整型
char 字符串,也可以用string、text
...
2)插入一条数据:
完整数据插入:
insert into student values(1, ‘zhangsan', 80);
注意:字符串zhangsan既可以用单引号‘zhangsan’,也可以用双引号“zhangsan”;
部分数据插入:
insert into student (no,name) values(2, 'lisi');
3)查询记录
完整数据查询:
select * from student;
部分数据查询:
select no,name from student;
按照条件查询:
select * from student where score=100;
select * from student where no=1 and score=100;
select * from student where no=1 or score=100;
4)删除记录:
删除某一条记录:
delete from student where name='lisi';
删除整张表数据:
delete from student;
5)更新记录:
update student set name=‘lisi’ where id=3;
update student set name='lisi',score=80 where id=2;
6)在表中增加一列
alter table student add column address char
7)在表中删除一列:
不支持直接删一列:
1)创建一个新的表并从原有表中提取字段;
create table stu as select id, name, score from stud