iOS中的資料的儲存方式

2022-05-07 08:45:11 字數 4210 閱讀 4415

資料庫儲存資料的步驟



什麼是sql語句

sql語句的特點

sql中的常用關鍵字有

select、insert、update、delete、from、create、where、desc、order、by、group、table、alter、view、index等等

資料操作語句(dml:data manipulation language)

資料查詢語句(dql:data query language)

integer : 整型值

real : 浮點值

text : 文字字串

blob : 二進位制資料(比如檔案)

為了保持良好的程式設計規範、方便程式設計師之間的交流,編寫建表語句的時候最好加上每個欄位的具體型別

drop table 表名 ;

drop table if exists 表名 ;

insert into 表名 (欄位1, 欄位2, …) values (欄位1的值, 欄位2的值, …) ;

insert into t_student (name, age) values (『zhangsan』, 10) ;

update 表名 set 欄位1 = 欄位1的值, 欄位2 = 欄位2的值, … ; 

update t_student set name = 『jack』, age = 20 ; 

delete from 表名 ;

delete from t_student ;

where 字段 = 某個值 ;   // 不能用兩個 =

where 字段 is 某個值 ; // is 相當於 =

where 字段 != 某個值 ;

where 字段 is not 某個值 ; // is not 相當於 !=

where 字段 > 某個值 ;

where 欄位1 = 某個值 and 欄位2 > 某個值 ; // and相當於c語言中的 &&

where 欄位1 = 某個值 or 欄位2 = 某個值 ; // or 相當於c語言中的 ||

update t_student set age = 5 where age > 10 and name != 『jack』 ;

delete from t_student where age <= 10 or age > 30 ;

update t_student set score = age where name = 『jack』 ;

select 欄位1, 欄位2, … from 表名 ;

select * from 表名; // 查詢所有的字段

select name, age from t_student ;

select * from t_student ;

select * from t_student where age > 10 ; // 條件查詢

select 欄位1 別名 , 欄位2 別名 , … from 表名 別名 ; 

select 欄位1 別名, 欄位2 as 別名, … from 表名 as 別名 ;

select 別名.欄位1, 別名.欄位2, … from 表名 別名 ;

select name myname, age myage from t_student ;

select s.name, s.age from t_student s ;

select count (字段) from 表名 ;

select count ( * ) from 表名 ;

select count (age) from t_student ;

select count ( * ) from t_student where score >= 60;

select * from t_student order by 字段 ;

select * from t_student order by age ;

預設是按照公升序排序(由小到大),也可以變為降序(由大到小)

select * from t_student order by age desc ;  //降序

select * from t_student order by age asc ; // 公升序(預設)

select * from t_student order by age asc, height desc ;

先按照年齡排序(公升序),年齡相等就按照身高排序(降序)

select * from 表名 limit 數值1, 數值2 ;

select * from t_student limit 4, 8 ;

可以理解為:跳過最前面4條語句,然後取8條記錄

limit常用來做分頁查詢,比如每頁固定顯示5條資料,那麼應該這樣取資料

第1頁:limit 0, 5

第2頁:limit 5, 5

第3頁:limit 10, 5

…第n頁:limit 5*(n-1), 5

select * from t_student limit 7 ;

相當於select * from t_student limit 0, 7 ;

表示取最前面的7條記錄

示例

create table t_student (id integer, name text not null unique, age integer not null default 1) ;

name欄位不能為null,並且唯一

age欄位不能為null,並且預設為1

什麼是主鍵

主鍵設計的原則

create table t_student (id integer primary key, name text, age integer) ;

integer型別的id作為t_student表的主鍵

如果想要讓主鍵自動增長(必須是integer型別),應該增加autoincrement

create table t_student (id integer primary key autoincrement, name text, age integer) ;

新建乙個外來鍵

create table t_student (id integer primary key autoincrement, name text, age integer, class_id integer, constraint fk_t_student_class_id_t_class_id foreign key (class_id) references t_class (id)); 

t_student表中有乙個叫做fk_t_student_class_id_t_class_id的外來鍵

表連線的型別

示例

select s.name,s.age from t_student s, t_class c where s.class_id = c.id and c.name = 『6(1)』;

ios中的資料儲存方式

1.nskeyedarchiver 採用歸檔的形式儲存資料,該資料物件需要遵守nscoding協議,並且該物件對於的類必須提供encodewithcoder 和initwithcoder 方法。前乙個方法為編碼的方法,後乙個我解碼的方法。2.nsuserdefaults 類似於android中的sh...

iOS中資料儲存方式

首先我們來了解一下ios中資料儲存有哪些方式 xml 屬性列表 plist 歸檔 plist 全名是 property list,屬性列表檔案。它是一種用來儲存序列化後的物件的檔案。屬性列表檔案的擴充套件名為 plist,因此通常被稱為 plist 檔案。檔案是 xml格式的。它是以 key val...

IOS開發中的資料儲存方式

ios 開發中,一般有如下幾種資料儲存方式。需要根據具體的業務場景,選擇 合適的資料儲存方式。1 使用者預設設定 這種情況通常不需要使用者干預,如遊戲通關資訊,video 退出之後,下次進入時,希望恢復到退出時的情況。2 設定束 settings bundle 提供了乙個通過 iphone ipad...