Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 15:22:53
Original
1120 people have browsed it

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;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!