开发中常用的简单SQL语句

创建表: create table if not exists 表名 (字段名1, 字段名2...);
create table if not exists t_student (id integer primary key autoincrement, name text not null, age integer)

增加数据: insert into 表名 (字段名1, 字段名2, ...) values(字段1的值, 字段2的值, ...);
insert into t_student (name,age) values (@"Jack",@17);

根据条件删除数据: delete from 表名 where 条件;
delete from t_student where name = @"Jack";

删除表中所有的数据: delete from 表名
delete from t_student

根据条件更改某个数据: update 表名 set 字段1 = '值1', 字段2 = '值2' where 字段1 = '字段1的当前值'
update t_student set name = 'lily', age = '16' where name = 'Jack'

根据条件查找: select * from 表名 where 字段1 = '字段1的值'
select * from t_student where age = '16'

查找所有数据: select * from 表名
select * from t_student

删除表: drop table 表名
drop table t_student

排序查找: select * from 表名 order by 字段
select from t_student order by age asc (升序,默认) select from t_student order by age desc (降序)

限制: select * from 表名 limit 值1, 值2
select * from t_student limit 5, 10 (跳过5个,一共取10个数据)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 50个常用的sql语句Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname...
    哈哈海阅读 4,979评论 0 7
  • 一、SQL语句如果要在程序运行过程中操作数据库中的数据,那得先学会使用SQL语句1.什么是SQLSQL(struc...
    命运建筑师fly阅读 7,722评论 0 2
  • 今天进行了小考试,考试中一开始特着急,出错了好几次,后来及时发现了,觉得正常对待就可以,以后就越来越稳了,灯的功能...
    庞爽阅读 681评论 0 0
  • 你曾有过什么样的浪漫,在你过往的某个时光里一度成为你快乐的源泉? 08至09年,因为一个姑娘在全年级收集中性笔笔芯...
    端木不帅阅读 2,563评论 0 2