SQLite3 使用总结

命令行

1 打开对应数据库文件

sqlite3 数据库名.db

例如:

sqlite3 filename.db

注:当前路径下需要有当前文件

dir 	# 是windows下查询当前路径下所有文件的命令
ls 		# 是linux下查询当前路径下所有文件的命令
		# Windows PowerShell软件两个命令都支持

2 显示数据库

.database

3 显示表信息

3.1 显示数据中所有的表名

.table

3.2 显示表的字段信息

pragma table_info(表名);

例如:

pragma table_info("user");

4 退出

.quit
.exit
ctrl + c

语法

1 建表

drop table if exists user;
create table user(
    user_id char(20) primary key,
    user_password char(20) not null
);

2 向表中插入信息

insert into 表名(表的参数) values(对应数据)
注意:表的参数可以为空,那么对应values里的值是按顺序赋值,否则按照 表的参数 来赋值

例如:

insert into user("user_id", "user_password") values("Lese", "123");
insert into user values("lll", "111");
注意末尾的分号!!!

3 查询表中的信息

select 参数 from 表名 (where 指定参数 = 指定值) (order by 指定条件 [desc|asc|]) (limit i,n);
注:如果参数为*,那么结果为所有列信息;where条件可以省略,省略表示查询所有行信息
order by表示排序条件,可以省略,desc为降序,asc和不填为升序
limit表示限制查询返回的数量,i为起点,n为数量(注意数据从0开始)
圆括号内的参数表示可填可不填,方括号内的参数为填的选项
在参数前面添加distinct表示去重

例如:

select * from problem;
select id from problem;
select * from problem where id = 1001;
select * from problem order by id desc;
select * from problem order by id;
select * from problem limit 0,2;
select distinct * from problem;

4 删除表内信息

delete from 表名 where 指定参数 = 指定参数值;

例如:

delete from user where user_id = 'lll';

5 修改表内的信息

update 表名 set 需要修改的参数 = 修改后的值 where 指定参数 = 指定参数值;
注意:修改操作是根据指定参数来确定对应数据的位置

例如

update user set user_password = "123456" where user_id = "Lese";

6 删除表

drop table 表名

例子:

drop table problem;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值