>  기사  >  데이터 베이스  >  iOS开发-数据库-sqlite操作1

iOS开发-数据库-sqlite操作1

WBOY
WBOY원래의
2016-06-07 15:22:531160검색

1. sqlite是弱类型的,创建表的时候可以不设置字段类型,用的比较多的几种类型:integer,text,blob,oc中支持NSNumber,NSString,NSData 2. 可以将某一个字段设置成主键、唯一键 主键,一个表里边只有一个主键; 唯一键 unique 1)sqlite3 data.db 打开数

1. sqlite是弱类型的,创建表的时候可以不设置字段类型,用的比较多的几种类型:integer,text,blob,oc中支持NSNumber,NSString,NSData

2. 可以将某一个字段设置成主键、唯一键

主键,一个表里边只有一个主键; 唯一键 unique

1)sqlite3 data.db 打开数据库,如果不存在就创建

2).table 查看表 .quit退出

3)create table students(id, name); 创建一个表

但是创建表的语句一般写成这样create table if not exists students(id, name);

create table students(id integer primary, name text);

create table students(id integer primary key auto increment, name text);

4)drop table students; 删除一张表

5)insert into students(id, name) values(1, 'WangDaChui');插入一条语句

insert into students(id) values(2);这样也是可以的,但是name会为NULL,如果需要为空的话就可以插入‘’;

insert into students values(3, 'ZhangWei');这样也可以,但是必须插入全部字段;

6)delete from students;清空表

delete from students where id=2;删除某一条

delete from students where id

7)条件查询

select * from student;

select name from student;

select name from student where id=2;

select *from student limit 3;

select * from student order by id;

select * from student order by id asc;升序,默认

select * from student order by id desc;降序

select * from student order by id desc limit 3;最大的三个

select count(id) from student;

select sum(id) from student;

select avg(id) from student;

select * from student where id=3 or id=5;

8)修改

update students set name='all‘ where id = 1;

9)复制表

create table students2 as select * from students;

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.