iOS FMDB入门一(sql基础)

      鉴于coredata的恶心难用,SQLite这种关系型数据库成为大多开发者的选择。而fmdb又是一款非常好的SQLite的框架,简单易掌握。本教程会让你初步掌握其使用,共分三篇,第一篇是sql基础。

      首先介绍一款数据库管理软件,Navicat,支持包括SQLite内的大部分数据库(下载和安装自己动手啦)

《iOS FMDB入门一(sql基础)》 数据库和表的建立(点击左上角connection)
《iOS FMDB入门一(sql基础)》
《iOS FMDB入门一(sql基础)》 建表
《iOS FMDB入门一(sql基础)》
《iOS FMDB入门一(sql基础)》

执行sql语句

    这条语句的作用是向t_student表中插入一行 name为lucy,score为80。后面的sql语句都可以通过New Query执行。

SQL语句

   sql语句注意三点:1.不区分大小写 2.必须以分号结尾 3.避免使用关键字命名字段

创表

 create table if not exists t_student(id integer primary key autoincrement,name text not null,age integer default 18,score real);

创建一个表t_student:

主键为id,自增,整型,

name 字符型 非空;

age 整型 默认值18;

score 浮点型。

插入

insert into t_student (name,age,score) values(‘Lucy’,19,88);

更新

update t_student set name=’Jack’;

删除

delete from t_student;

查询

select * from t_student ;(*代表所有)

条件语句 对符合条件的记录进行操作

关键字 where 连接字 and or

delete from t_student where age>10 and score<80;

select * from t_student where age<22;

select count (*) from t_student where age>18;//得到符合条件的记录数量

排序

select * from t_student where age>20 order by score desc;(默认是升序asc) 

限制

select * from t_student limit 3,5;前三条不取 取接下来的五条

关于更多sql语句的知识,如表连接和外键等可自行去w3school学习

SQL 教程

    原文作者:QJK
    原文地址: https://www.jianshu.com/p/80c7b2c6a82e
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞