FMDB 基本的数据库语句

2017-10-23  本文已影响0人  小孩仔
1.创建表: create table if not exists 表名 (字段名1, 字段名2...);
    例如:创建 t_student 表 id(id自增长) create table if not exists t_student (id integer primary key autoincrement, name text not null, age integer) 
2.增加数据: insert into 表名 (字段名1, 字段名2, ...) values(字段1的值, 字段2的值, ...);
 例如:在 t_student 表插入name,age字段 insert into t_student (name,age) values (@"Jack",@17);
3.删除数据

3.1 根据条件删除数据: delete from 表名 where 条件;

  例如:删除 t_student 表中 name 字段为 Jack 的数据 delete from t_student where name = @"Jack"; 

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

  例如: delete from t_student; 
4.根据条件更改某个数据 update 表名 set 字段1 = '值1', 字段2 = '值2' where 字段1 = '字段1的当前值'
  例如: update t_student set name = 'lily', age = '16' where name = 'Jack' 
5根据条件查询

5.1根据条件查找 select from 表名 where 字段1 = '字段1的值'

  例如: select from t_student where age = '16' 

5.2查找所有数据 select from 表名

  例如: select from t_student 

5.3排序查找: select from 表名 order by 字段

  例如: 1.select from t_student order by age asc (升序,默认)
        2.select * from t_student order by age desc (降序)
6.删除表: drop table 表名
  例如: drop table t_student
上一篇 下一篇

猜你喜欢

热点阅读