SQLite 数据库的相关命令集合

举报
王建峰 发表于 2021/11/19 03:22:33 2021/11/19
3k+ 0 0
【摘要】 SQLite是一种嵌入式数据库,它的数据库就是一个文件。由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成。   命令操作(Linux环境) 1, 数据库的安装      sudo apt-get ins...

SQLite是一种嵌入式数据库,它的数据库就是一个文件。由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成。

命令操作(Linux环境)

1, 数据库的安装

     sudo apt-get install sqlite
 

2, 数据库命令:


      1)系统命令 , 都以'.'开头


               .exit
               .quit
               .table   查看表
               .schema  查看表的结构
  
 


          
      2)sql语句, 都以‘;’结尾


              1-- 创建一张表
                  create table stuinfo(id integer, name text, age integer, score float);
              2-- 插入一条记录
                  insert into stuinfo values(1001, 'zhangsan', 18, 80);
                  insert into stuinfo (id, name, score) values(1002, 'lisi', 90);
              3-- 查看数据库记录
                  select * from stuinfo;
                  select * from stuinfo where score = 80;
                  select * from stuinfo where score = 80 and name= 'zhangsan';
                  select * from stuinfo where score = 80 or name='wangwu';
                  select name,score from stuinfo;  查询指定的字段
                  select * from stuinfo where score >= 85 and score < 90;
              4-- 删除一条记录
                  delete from stuinfo where id=1003 and name='zhangsan';
              5-- 更新一条记录
                  update stuinfo set age=20 where id=1003;
                  update stuinfo set age=30, score = 82 where id=1003;
              6-- 删除一张表
                  drop table stuinfo;
              7-- 增加一列
                  alter table stuinfo add column sex char;
              8-- 删除一列
                  create table stu as select id, name, score from stuinfo;
                  drop table stuinfo;
                  alter table stu rename to stuinfo;
  
 

     PS:如果要讲数据库的id字段设置主键,并指定自增长类型需要添加primary key 和 autoincrement这连个类型

     create table info(id integer primary key autoincrement, name vchar);
 

文章来源: blog.csdn.net,作者:hinzer,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/feit2417/article/details/81877090

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。