美文网首页
sqlite常用语句总结

sqlite常用语句总结

作者: Hris | 来源:发表于2017-06-29 15:51 被阅读11次

    //创建表格

    create table 表名(字段名1 字段类型1,字段名2,字段类型2,字段名3 字段类型3,....)

    create table if not exists 表名(字段名 1字段类型1,字段名2 字段类型2,...)

    egg: create table student(name text,age integer,score real)

    //字段类型

    integer:整形

    real:浮点型

    text:文本字符串

    // 删除表

    drop table 表名

    egg:drop table student

    // 插入数据

    insert into 表名(字段1,字段2,字段3,..)values(字段1的值,字段2的值,字段3的值,…)

    egg:insert into student(name,age) values(‘夏明’,10);

    注释:注意数据库总的字符串的内容应该用单引号括住

    //更新数据

    update 表名 set 字段1=字段1的值,字段2=字段2的值.字段2=字段2的值

    egg:update table set name=‘木木’,age=8;

    注释:注意上面的实例会将student表中的所有记录的name和age都会修改

    // 删除数据

    delete from 表名

    egg:delete from student

    注释:上述会将表student中的所有数据都会删除

    //分页查询指令

    limit 指令用于限制查询出来的结果数量

    · 第一个数值表示从哪条记录开始(起始位置为0)

    · 第二个数值表示一次读取多少条记录,如果是分页的话,通常第二个数值固定不变,表示每页需要显示的记录条数

    · 第一页

    select * from student limit 0,3

    · 第二页

    select * from student limit 3,3

    //查询排序

    · ASC 升序(默认的排序方法)

    · DESC 降序

    select * from student order by age ASC,id DESC;

    //能够定向地查到具体需要的内容

    · 从数据库中查找名字叫小明的记录

    select * from student where name=‘小明’

    · 从数据库中查出名字以wang开头的记录

    select * from student where name like ‘wang%’;

    · 从数据库中查询包含wang的所有记录

    select * from student where name like ‘%wang%’

    //对数据进行统计

    · 取出所有数据的总数目

    select count(*)from student

    · 统计所有符合条件的记录条数

    select count (*) from student where name like ‘wang%’;

    · 选出指定列中的最大值

    select max(age) from student;

    · 选出指定列中最小值

    select min(age) from student

    · 计算指定列中的平均值

    select avg(age) from student

    //更新指令

    · 更新一个字段

    update  student set name=‘小h’where name=‘小明’

    · 更新多个字段,每个字段之间需要用,分开

    update student set name=‘hpng’,age=6 where name=‘小明’

    注释:需要注意的是: 在使用更新指令的时候,最好是能够准确的知道唯一的一条更新的记录,否则其他所有满足的调价的记录都是会被修改的

    自动增长是有服务器来控制的

    相关文章

      网友评论

          本文标题:sqlite常用语句总结

          本文链接:https://www.haomeiwen.com/subject/nkwmcxtx.html