關(guān)于數(shù)據(jù)庫(kù)的淺顯認(rèn)知#
-什么是數(shù)據(jù)庫(kù)?
-數(shù)據(jù)的集散地,能夠有效的存儲(chǔ)和管理數(shù)據(jù)
-關(guān)系型數(shù)據(jù)庫(kù):關(guān)系型數(shù)據(jù)庫(kù):1. 用二維表組織數(shù)據(jù); 2. 結(jié)構(gòu)化查詢語(yǔ)言(SQL - Structured Query Language)
-表:行表示一條記錄
-列表示一個(gè)字段
-主鍵:能夠唯一標(biāo)識(shí)一條記錄的字段
-外鍵:其他表的主鍵(外來(lái)的主鍵)
輕量級(jí)SQL的使用##
-DDL - 數(shù)據(jù)定義語(yǔ)言 create / drop / alter
-DML - 數(shù)據(jù)操作語(yǔ)言 insert / delete / update
-DQL - 數(shù)據(jù)查詢語(yǔ)言 select
-DCL - 數(shù)據(jù)控制語(yǔ)言 grant / revoke
下面我們用一個(gè)列子具體演示一下sql的使用##
-第一步,創(chuàng)建一張表,列入穿件一張賬目記錄的表
create table TbStudent --(前綴表示類(lèi)型)
(
stuid integer primary key, --設(shè)置主鍵primary key
stuname varchar(20) not null, --設(shè)置姓名字符可變20個(gè)字符,后面定義不能為空
stusex char(1) default'男',
stuaddr varchar(50), --允許為空
stubirth date —(最后一項(xiàng)不打逗號(hào))
); --分號(hào)表示據(jù)結(jié)束
-使用第三方庫(kù)FMDB,在xcode中創(chuàng)建如下
//創(chuàng)建數(shù)據(jù)庫(kù)表
[_fmdb executeUpdate:@"create table TbStudent(stuid integer primary key,stuname varchar(20) not null,stusex char(1) default'男',stuaddr varchar(50),stubirth date);"];
-修改信息,例如,添加列
-alter table TbStudent add stubirth date;
-插入信息
-nsert into TbStudent values(1001,'***','男','云南某處','1980-11-28');
-查詢所有行所有列
-select * from TbStudent;
-刪除數(shù)據(jù)
-delete from TbStudent where stuid=1003;
-更新數(shù)據(jù),修改數(shù)據(jù)
-update TbStudent set stuaddr='四川綿陽(yáng)',stubirth='1990-4-5' where stuid=1002;
-一般來(lái)說(shuō)程序中有增刪改以后就能應(yīng)付一些輕量級(jí)的數(shù)據(jù)應(yīng)用了
一點(diǎn)點(diǎn)正則表達(dá)式的用法#
//創(chuàng)建數(shù)據(jù)庫(kù)表
//方括號(hào)內(nèi)表示任取其一,花括號(hào)表示限制
//NSString *regex=@"[_a-zA-Z0-9]{6,20}";
//\w代表字母數(shù)字下滑線,但在oc中要兩個(gè)下劃線,第一根表示轉(zhuǎn)義字符
// NSString *regex=@"\\w{6,20}";
// NSString *tel=@"13345678900";
// NSString *regex1=@"1[345678][0-9]{9}";
//大寫(xiě)的\D表示非數(shù)字 ,[^345678]表示不能是346578
// NSString *regex1=@"1[345678]\\d{9}";
NSString *qq=@"123456123456";
NSString *regex=@"[1-9][0-9]{4,11}";
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([predicate evaluateWithObject:qq]) {
NSLog(@"有效?。。?!");
}else{
NSLog(@"卵了");
}