1.系统命令
以“.”开头的命令
.help 帮助
.q或.quit 退出
.exit 退出
.schema 查看表的结构图
2.sql命令
基本的sql命令,不易以“.”开头,但都要以“;”结尾。
sql语句不检查类型是否匹配,所以写的时候小心。
创建一张数据库表,表名叫stu
create table stu(id Integer,name char,score Integer);
插入一条内容
insert into stu values(1001,‘zhang’,99);//插入所有字段内容
insert into stu(name,score)values(1001,‘zhang’,99);//插入部分字段内容
查询数据库内容
select * from stu;//查询所有字段内容
select name,score from stu;//查询部分字段内容
按照条件查询:
select * from stu where score=80;
select * from stu where score=80 and name=‘zhangsan’;
select * from stu where score=80 or name=‘lisi’;
删除数据
delete from stu;删除了整张表;
delete from stu where score=‘90’;//删除分数为90的数据
也可以用and和or搭配进行使用
更新数据
update stu set name=‘wangwu’where id = 1001;//将id=1001的数据的name改为wangwu;
update stu set name=‘wangwu’,score = 98 where id = 1001;//注意此处不能用and,是“,”
插入一列
alter table stu add column address char;//column为列的意思
删除一列
sqlite3不支持直接删除一列,如果删除列需要以下几步:
(1)创建一张新的表
create table stu1 as select id,name from stu;
(2)删除原有的表
drop table stu;
(3)将新的表名字改为原有旧表的名字
alter table stu1 rename to stu;
//新的表中就没有score这一项了
复制代码
转载于:https://juejin.im/post/5b54813de51d45616f459294