SQLite初体验

一、SQLite3 数据库安装

        1、本地安装

sudo dpkg -i *.deb

        2、在线安装

sudo apt install sqlite3

       3、检查是否安装完成

sqlite3 -version

二、SQLite3 基本命令

        1、系统命令

                以 “.” 开头的命令

                .help        帮助

                .quit        退出

                .exit        退出

                . schema        查看表的结构图

                .databases        查看当前系统打开的数据库

                .table        查看当前数据库的表

        2、sql命令

                基本的sql命令,不以 “.” 开头,但都要以 “;” 结尾

                创建一张数据库表 stu

// 不带主键
create table stu(id Integer, name char, score Integer);

// 带主键
create table stu(id Integer primary key, name char, score Integer);

                 插入一条记录

// 完整插入
insert into stu values(1001, 'zhangsan', 80);

// 部分插入
insert into stu(id,name) values(1002,"lisi");

                 查询记录         

// 查询所有字段的结果
select * from stu;

// 查询数据库中的部分字段的内容
select name,score form stu

// 条件查询
select * from stu where score=80;
select * from stu where score=80 and name='zhangsan';
select * from stu where score=80 ro name='lisi';

                删除记录

// 删除一整个表记录
delete from stu

// 删除一条记录
delete from stu where name='lisi';

               更新记录

// 单字段更改
update stu set name='wangwu' where id=1001;

// 多字段更改
update stu set name='zhaoliu',score=100 where id 1001;

                插入一列

alter table stu add column address char;

                删除一列

// SQLite3 不支持直接删除一列

// 1. 创建一张新表
create table stu1 as select id,name,score from stu;

// 2. 删除原有的表
drop table stu;

// 3. 将新表名字改成原有旧表名字
alter table stu1 rename to stu;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值