ios UI數據庫 sqlite小型數據庫的增、刪、改、查、排序

pwmd 9年前發布 | 12K 次閱讀 Objective-C IOS

#import "table.h"


@implementation table


// 1.創建表 每一列之間用',',如果存在就不創建

create table if not exists t_class(

                                   class_id integer primary key autoincrement,

                                   class_name varchar,

                                   person_count integer default )


// 1.1// 刪除表

drop table if exists t_person


// 2.插入數據(增),因為設置id為自增,所以不輸入直接為1


insert into t_class (class_name,person_count) values('class1',10)


// 3.刪除數據(刪)

// table里的全刪  deleta from t_class

// 刪除指定id=5的數據    delete from t_class where class_id=5


// 4.修改數據

name全改成newclassname     update t_class set class_name='newclassname'


 修改某一行的某個數據 update t_class set class_name='newclassname' where class_id=7


// 5.查詢數據(查)

 查詢所有             select * from "t_class"

 查詢指定一個或者幾個數據                select class_id,person_count from t_class where class_name='oldname'


關鍵字 and or

select class_id,person_count from t_class where class_id=7 and person_count=20

select class_id,person_count from t_class where class_id=7 or person_count=20

select class_id,person_count from t_class where class_id between 7 and 20


// in like不需要非要查主鍵

select class_id,person_count from t_class where class_id in(7,9) // 在7和9的

select class_id,person_count from t_class where class_id not in(7,9)// 不在7和9的

select class_id,person_count from t_class where class_name like 'new%' //以new開頭

select class_id,person_count from t_class where class_name like '%class' // 以new結尾


// 獲取表的數據總數 在count(*)后面加名字可以起別名

select count(*) number from t_class // count1是按第一列來統計,一般以主鍵列統計一般寫*就可以


// 獲取最小值

select min(person_count) from t_class


// 獲取最大值

select min(person_count) from t_class


// 獲取平均值

select avg(person_count) from t_class


// 獲取總成績

select sum(person_count) from t_class


// 獲取絕對值

select abs(person_count) from t_class


// 在不修改數據的前提下查詢結果去除前后空格

select trim(class_name) from t_class


// 替換

select replace(class_name,'c','o') from t_class


// 長度(空格也算長度)

select length(class_name) from t_class


// 日期函數

select date() from t_class

select datetime() from t_class


// 判斷為空

select * from t_class where class_name is null


// 排序

select * from t_class order by class_id desc (倒序)

select * from t_class order by class_id asc   (正序、asc可省默認正序)


@end

 本文由用戶 pwmd 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!