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

(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 from t_student s, t_class c where s.class_id = c.id and c.name = ‘2’;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值