利用终端练习sqlite的操作

来源:互联网 发布:sqlserver数据库连接 编辑:程序博客网 时间:2024/05/07 16:59
首先是创建一个文件来保存sql文件=>mkdir sqlite
进入sql文件所在的目录=>  cd sqlite/=> sqlite3 data.db
创建一张data表
create table Students(id,name,score);
创建一张data表,如果不存在,就创建,如果存在,就不创建
create table if not exists Students(id,name,score);
查看数据库有几张表
.table 
删除表
drop table
插入一条数据
insert into Students values(0,' 令狐冲',90);
查询表格里面内容
select * from Students;
第二种添加数据的方式
insert into Students(id,name,score)values(2,'张无忌',90);
显示当前路径
.databases
修改数据
update Student set name = '东方不败' where id = 2;
删除一条数据
delete from Students where id = 3;
查询前三条数据
select * from Students limit 3;
查询表中的name字段名称的所有数据
select  name from Students;
查询表中name,score两个字段的所有数据
select name,score from Students;
顺序排序
select * from Students order by score;
逆序排序
select * from  Students order by score desc;
最前面的三名
select * from Students order by score desc limit 3;
修改主键id的值
update GongFU set id = 1 where id = 2;
建立两表之间的查询
select Students.id,Students.name,Students.score,GongFU.name from Students,GongFU where Students.id = GongFU.id;
查找某个表中有多少个元素
select * count(*)from Students;
原创粉丝点击