swift SQLite使用

1.DDL

1.创建表

 create table if not exists t_student(id integer auto_increment primary key ,name 
 varchar(3) , age int);
  1. 删除表
drop table if exists t_student;
  1. 修改表结构
alter table t_student add address varchar(4);
alter table t_student modify address varchar(6) not null;

tip:
简单约束:
name varchar(3) not null
age int default 66
主键约束:
id integer auto_increment primary key

2. DML

1.插入数据

insert into  t_student(name,age,address) values ('xiaoM',12,'guangzhou');

2.修改数据

update t_student set name='xiaoHuang' where id=1;

3.删除数据

delete from t_student where id= 1 ;

tip:
条件约束
delete from t_student where id is 1 or name = 'xiaoM';

3. DQL

查询语句
1.查询所有字段信息

select * from t_student;

2.查询部分字段信息

select name,age from t_student;

3.查询符合条件下的部分字段信息

select name,age from t_student where id=2;

4.查询数据个数

select count(*) from t_student;

5.查询age不为空值的个数

select count(age) from t_student;

6.查询age平均值

select avg(age) from t_student;

7.查询age总和

select sum(age) from t_student;

8.查询age最大值

select max(age) from t_student;

9.查询age最小值

select min(age) from t_student;

10.查询按分数升序,按年龄降序

select *from t_student order by score asc, age desc;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容