版权声明:本文为博主原创文章,转载请注明出处。 https://www.cnblogs.com/YaoYing/p/12067194.html

打开SQLite3文件

sqlite3 student.db
//打开student.db数据库,如果没有该文件就创建

系统命令

.开头的命令,列举如下

.databases     查看打开的数据库
.table 查看数据库表格
.schema 查看表的结构图
.help 帮助
.quit 退出
.exit 退出

操作命令

不以.开头,但以;结尾的命令,列举如下

创建数据库表
create table 表名(字段名 数据类型...);

create table student(id integer, name char, score integer);
//student 数据库表名
//id 学生的学号
//name 学生的名字
//score 学生的分数
//integer 整数类型
//char 字符类型
插入数据
insert into 表名 values(第一字段,第二字段,第三字段...);
insert into 表名 (需插入的字段) values(第一列数据,第二列数据,第三列数据...); insert into student values(1, “zhangsan”, 80);
//插入全部数据
insert into student (id, name) values(2, "lisi");
//只插入id和名字
insert into student (name, score) values("wangwu", 99);
//只插入名字和分数
查询数据
select * from 表名;
select 字段... from 表名;
select * from 表名 字段=值;
select * from 表名 字段=值 and 字段=值;
select * from 表名 字段=值 or 字段=值; select * from student;
//查询student表全部数据
select name, score from student;
//查询student表name字段和score字段全部数据
select * from student where score=80;
//查询student表score字段等于80分的数据
select * from student where name="zhangsan" and score=80;
//查询student表name字段是zhangsan且score字段是80分的数据
select * from student where name="zhangsan" or score=80;
//查询student表name字段是zhangsan或score字段是80分的数据
删除数据
delete from 表名;
delete from 表名 where 字段=值; delete from student;
//删除student表所有数据
delete from student where score=90;
//删除student表中score等于90分的数据
更新数据
update 表名 set 要修改字段=值 where 需修改字段=值;
update 表名 set 要修改字段=值, 要修改字段=值 where 需修改字段=值; update student set name="zhangsan" where id=1;
//把student表中id字段等于1的这条数据name字段修改为zhangsan
update student set name="zhangsan", score=88 where id=1;
//把student表中id字段等于1的这条数据name字段修改为zhangsan,score字段修改为88
插入字段
alter table 表名 add column 字段名 字段类型;

alter table student add column address char;
//往student表中插入数据类型为char的address字段
删除字段

SQLite3不支持直接删除,可通过以下方法间接删除某字段

从旧表中复制需要保留的字段到新表中

create table 新表名 as select 需要的字段... from 旧表名;

create table student1 as select id, name, address from student;
//创建一个新的student1表,从旧表student中拷贝id字段、name字段、address字段

删除旧表

drop table 表名;

drop table student;

把新表的表名修改为旧表的表名

alter table 新表名 rename to 旧表名;

alter table student1 rename to student;

更新日期20191219

如有任何问题,请评论或者私信,非常感谢

最新文章

  1. Spring MVC学习
  2. LeetCode #329. Longest Increasing Path in a Matrix
  3. 繁华模拟赛day8 牛栏
  4. Net框架下-ORM框架LLBLGen的简介
  5. Could not find the Visual SourceSafe Internet Web Service connection information for the specified database Would you like to launch the Visual sourceSafe connection wizard?
  6. 在VS2012中编译WinXP兼容的程序
  7. clip属性
  8. mvn详解
  9. bzoj1306
  10. Object-c学习之路五(@protocol协议)
  11. SSH报错分析
  12. iOS 应用关于弥补安全优化问题
  13. Python-Blog2-编写Web app 骨架
  14. C# 中?和??的用法
  15. TensorRT&Sample&Python[network_api_pytorch_mnist]
  16. java安装与配置
  17. C/C++ 类成员函数指针 类成员数据指针
  18. C#使用PriorityQueue
  19. linux find/grep 与cat联合使用
  20. BZOJ 3329 Xorequ:数位dp + 矩阵快速幂

热门文章

  1. 磁盘格式化、磁盘挂载、手动增加swap空间 使用介绍
  2. TypeScript躬行记(1)——数据类型
  3. 程序员修神之路--打通Docker镜像发布容器运行流程
  4. Python协程与Go协程的区别二
  5. luogu P1168 中位数 |树状数组+二分
  6. iOS开发-KVO的奥秘
  7. Java修炼——递归算法的俩个实例
  8. Go语言学习之路
  9. asp.net core 配置微信返回信息接口
  10. Newman