關(guān)于數(shù)據(jù)庫的淺顯認(rèn)知#
-什么是數(shù)據(jù)庫?
-數(shù)據(jù)的集散地,能夠有效的存儲和管理數(shù)據(jù)
-關(guān)系型數(shù)據(jù)庫:關(guān)系型數(shù)據(jù)庫:1. 用二維表組織數(shù)據(jù); 2. 結(jié)構(gòu)化查詢語言(SQL - Structured Query Language)
-表:行表示一條記錄
-列表示一個(gè)字段
-主鍵:能夠唯一標(biāo)識一條記錄的字段
-外鍵:其他表的主鍵(外來的主鍵)
輕量級SQL的使用##
-DDL - 數(shù)據(jù)定義語言 create / drop / alter
-DML - 數(shù)據(jù)操作語言 insert / delete / update
-DQL - 數(shù)據(jù)查詢語言 select
-DCL - 數(shù)據(jù)控制語言 grant / revoke
下面我們用一個(gè)列子具體演示一下sql的使用##
-第一步件相,創(chuàng)建一張表,列入穿件一張賬目記錄的表
create table TbStudent --(前綴表示類型)
(
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)不打逗號)
); --分號表示據(jù)結(jié)束
-使用第三方庫FMDB夜矗,在xcode中創(chuàng)建如下
//創(chuàng)建數(shù)據(jù)庫表
[_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='四川綿陽',stubirth='1990-4-5' where stuid=1002;
-一般來說程序中有增刪改以后就能應(yīng)付一些輕量級的數(shù)據(jù)應(yīng)用了
一點(diǎn)點(diǎn)正則表達(dá)式的用法#
//創(chuàng)建數(shù)據(jù)庫表
//方括號內(nèi)表示任取其一,花括號表示限制
//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}";
//大寫的\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(@"有效I耐弧6苑觥!惭缰!");
}else{
NSLog(@"卵了");
}