IOS线程数据篇12之Sqlite3其他属性:排列约束、外键约束、表连接

来源:互联网 发布:汉武大帝知乎 编辑:程序博客网 时间:2024/06/13 08:14

(1)别名

select s.名字,s.年龄 FROM t_student s where score > 95 and 年龄 < 17;


(2)查询数据统计

select count(名字) from t_student WHERE score > 96;

select count(*) from t_student WHERE score > 96;


(3) 查询排序 asc升序 dsc降序

select * FROM t_student where score > 90 and 年龄 < 20 ORDER BY score asc; 


也可以组合在一起使用,比如分数升序,年龄降序组合在一起。

(4)分页查询关键字limit

select * FROM t_student where score > 90 and 年龄 < 20 ORDER BY score asc LIMIT 2,1;


(5)简单约束规则

not null 规定字段不能为空 unique 规定字段的值必须唯一 default 设定字段值的唯一性

(6) 为表中添加新的字段

ALTER table t_student add 班级 text;


(7) 外键关联

Sqlite只允许使用creat的时候添加外键关联,不允许使用ADD CONSTRAINT variant of the ALTER TABLE。真是坑爹啊。

(8)表在上面一步建立连接之后可以使用连接查询:

select s.name,s.age fromt_student s,t_class c wheres.class_id =c.id and c.name = ‘2’;

0 0
原创粉丝点击