SQL 数据基本操作

2017-06-26  本文已影响9人  小饼干是只松鼠

SQL 数据基本操作

创建表:

CREATE TABLE IF NOT EXISTS t_students 
(id integer PRIMARY KEY AUTOINCREMENT,name text NOT NULL,age integer NOT NULL)

删除表:

1. dorp -- drop table tb -- 删除内容和定义,释放空间。简单来说就是把整个表去掉 (暴力)
2. truncate -- truncate table tb -- 删除内容、释放空间但不删除定义。只是清空表数据
3. delete -- delete table tb -- 删除内容不删除定义,不释放空间,虽然也是删除整个表的
   数据,系统逐行地删,效率较truncate低 
   
tb表示数据表的名字

增加信息:

insert into table(stu_name,stu_password,stu_login) values(?,?,?)"

修改信息:

update table set stu_name='zl',stu_password='zl123',stu_login='zhangsan'
where stu_id=4"

数据删除:

delete from team where stu_id=9

数据查询:

/*FMDB*/
// 查询数据
FMResultSet *rs = [db executeQuery:@"SELECT * FROM t_student"];
// 遍历结果集
while ([rs next]) {
NSString *name = [rs stringForColumn:@"name"];
int age = [rs intForColumn:@"age"];
double score = [rs doubleForColumn:@"score"];
// 1.创建model; 2.model赋值; 3.添加数组;
}

其他操作(搜索 查询)
基于FMDB简单的查询操作

上一篇 下一篇

猜你喜欢

热点阅读