https://www.runoob.com/sqlite/sqlite-commands.html

一 。linux 下安装数据库和创建一个数据库

1. Linux 下安装sqlite3 需要两个命令 即可

  (1) sudo apt-get install sqlite

   (2) sudo apt-get install libsqlite3-dev

2. 安装完后,创建一个数据库,终端下输入命令 【sqlite3 数据库名字 】数据库名字以 .db 结尾格式

  创建数据库student.db   【 sqlite3 student.db 

二 。数据库命令是以 【.】  开头的;数据库语句是以【;】结尾的

1. 数据库命令

  (1) .schema 表名    显示表结构 如:【 .schema student

  (2)【 .tables 】  显示表

  (3)【 .quit 】或 【 .exit 】 退出数据库控制界面

  

2. 数据库语句

  (1)创建一个数据表:student 【 create table student (id int primary key,name char,age int,sex char); 】  

  

  (2)向表中插入数据  insert into 表名 values (值1,值2,值3,值4); 如:【 insert into student values (0,'zhang0',20,'m'); 】 没有返回错误信息则插入成功

  

  

  (3)查找语句 select *from 表名;

      查找表中所有内容显示 【 select *from student;

      查找某个字段(列信息)【 select id from student;

      按照某个条件查找 【 select * from student where age>25 and sex='m' 】 { 条件 and  or 表示 与 ,或 }

  

  (4)修改某个内容 update 表名 set 列名=新值 where 条件;    如:把 zhang0 的名字改为 liwang 【update  student  set  name=‘liwang’   where  name=’zhang0‘; 

  

  (4)删除一条信息 :delete from 表名 where 条件;  如:删除名字为hello的一行内容 【 delete from student where name='hello';

  

  

  (5)添加一列 : alter table 表名 add 列名 数据类型; 【alter table student add address char;

  

  【update student set address='beijing';】 把地址字段全部更新为beijing

  

  (5)删除一个表  drop table 表名;  【 drop table soc; 

  

  (6)sqlite3不支持删除一列信息,可以 把原来的表里面的需要的列复制到一个新表,重新命名:create table 新表名 as select 列名1,列名2,列名3,列名4 from 旧表名;

    【 create table stu as select id,name,sex from student; 】 选择student表中的id,name,sex字段作为新表的字段

   

  (7)重新命名表 :alter table 旧表名 rename to 新表名;  【 alter table stu rename to student_new; 】  

   

  (8)select count(*) from sqlite_master where type="table" and name = "表名";

    注意:表示字符串可以是""或者''SQL语句结束必须是一个分号。

最新文章

  1. php的__clone __call
  2. 关系型数据库ACID
  3. python3和Python2的区别(被坑太久了)
  4. 网易云课堂_程序设计入门-C语言_期末考试编程题
  5. 交换A与B值的四种方法
  6. 你的第一个AngularJS应用--教程二:基架、建立和測试的工具
  7. .Net Core部署到CentOS
  8. hdu 1394 线段树
  9. Linux - 设置Centos控制台模式的分辨率
  10. 《深入理解 JVM 虚拟机》 --- 看书笔记
  11. ZOJ1008
  12. mysql执行update报错 Err] 1055 - 'information_schema.PROFILING.SEQ' isn't in GROUP BY
  13. redis持久化RDB与AOF
  14. iOS-微信支付商户支付下单id非法
  15. 使用LTP套件对Linux系统进行压力测试
  16. ubuntu 远程登录服务器和服务器中下载代码
  17. spring boot打jar包(maven对jar和lib分离)
  18. Oracle问题之ORA-12560TNS:协议适配器错误-转载
  19. Monitoring an IBM JVM with VisualVM
  20. VS开发Windows服务

热门文章

  1. 线性方程组迭代算法——Jacobi迭代算法的python实现
  2. 解决Redhat yum出现This system is not registered with RHN的方案
  3. java爬取读者文摘杂志
  4. JS浏览器事件循环机制
  5. Spring Boot中普通类获取Spring容器中的Bean
  6. KiCAD绘制电源符号
  7. Linux账号管理与ALC权限设定(一)
  8. linux 7 安装KVM
  9. 【Flutter学习】基本组件之文本组件Text
  10. (转)OpenFire源码学习之十一:连接管理(下)