sqlite3 基本操作


安装sqlite3:
sudo dnf install sqlite3  (Fedora)
sudo apt-get install sqlite3  (ubuntu)

1、打开数据库,如果没有则创建
    sqlite3 test.db
2、创建表格格式,表格 student 中 有 integer型的 id 作为主键,不能重复,text型的 name,使用时用双引号,浮点型的score,二进制型的sex
    sqlite> create table student (id integer primary key,name text,score real,sex blob );
3、查看当前数据库中所有的表.是sqlite3的操作符,末尾不加分号
    sqlite> .table
4、删除表格
    sqlite> drop table student ;
5、退出数据库
    sqlite> .quit
6、向表中添加元素 ( autoincrement 自动增长,用法如 id integer autoincrement  )
    sqlite> insert into student (id,name,score,sex)values( 1, "s1",95,1);
    sqlite> insert into student (id,             sex)values( 2,         0);
    sqlite> insert into student (id,     score)values( 3,     96 );
    sqlite> insert into student (id,name,score      )values( 4, "s4", 96);
7、查找数据
    sqlite> select score from student where id = 1 ;
    sqlite> select name , score from student where id = 1 ;
    sqlite> select * from student where id = 1 ;    
8、更改数据
    sqlite> update student set name = "st3" where id = 1 ;
    sqlite> update student set name = "st3" ,score = 100 where id = 1 ;
    sqlite> update student set name = "s3" where id = 1 and score = 100 ;
9、删除数据
    sqlite> delete from student where name = "s1";
    sqlite> delete from student where name = "s3" and score = 100;
10、判断表是否存在
    sqlite> select count(*) from sqlite_master where type = "table" and name = "student";
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值