1 為什么軟件測試工程師還需要學(xué)習(xí)數(shù)據(jù)庫以及開發(fā)方面的知識滋觉?
測試工程師在測試軟件過程中豌熄,不僅僅需要在界面進行操作顷歌,還需要檢查數(shù)據(jù)庫中的數(shù)據(jù)是否正確,從而在軟件出現(xiàn)問題時候邻储,能夠定位到問題原因赋咽,學(xué)習(xí)數(shù)據(jù)庫,掌握數(shù)據(jù)庫操作吨娜,增加面試成功機會脓匿,可以提高工資。
2 什么是數(shù)據(jù)庫
數(shù)據(jù)庫是按照數(shù)據(jù)的結(jié)構(gòu)來組織宦赠、存儲陪毡、和管理數(shù)據(jù)的倉庫米母,簡而言之,就是存放數(shù)據(jù)的倉庫
3 常見數(shù)據(jù)庫
1.Oracle
2.MySQL
3.SQLServer
4.MongoDB
5.Redis
4 數(shù)據(jù)庫和SQL是什么關(guān)系毡琉?
數(shù)據(jù)庫里面放著數(shù)據(jù)铁瞒,而SQL是用來操作數(shù)據(jù)庫里數(shù)據(jù)的語言(工具)。
DDL-數(shù)據(jù)庫定義語言: 數(shù)據(jù)庫定義語言桅滋,用于定義數(shù)據(jù)庫慧耍,用于定義表結(jié)構(gòu)
表中字段基本數(shù)據(jù)類型:大致可以分為三類:數(shù)值、日期/時間和字符串(字符)類型
數(shù)據(jù)庫語句操作:
CREATE DATABASE 數(shù)據(jù)庫名;
DML - 數(shù)據(jù)庫操作語言:數(shù)據(jù)庫操作語言丐谋,用以操作數(shù)據(jù)庫蜂绎。
//插入數(shù)據(jù)
//刪除數(shù)據(jù)
delete from student where id=1;
delete from student;
truncate table student;
. 修改數(shù)據(jù)
update student set age=age+10
update student set name=’張三’ where name=’zhangsan’
update student set salery=100.01,birthday=’1999-10-10’ where id=3;
DQL-數(shù)據(jù)庫查詢語言:數(shù)據(jù)庫查詢語言
排序查詢
MySQL中 升序為asc,降序為desc
升序:select * from 表名 order by 表中的字段 asc(MySQL中默認是升序排列笋鄙,可不寫) 师枣;
降序:select * from 表名 order by 表中的字段 desc ;
.分組查詢
分組查詢得到結(jié)果是第一次查到的某個組別萧落。
//創(chuàng)建一個訂單表
create table employee(id int,name varchar(20),sex varchar(20),age int);
insert into employee values(1,'sunsan','男',18);
insert into employee values(2,'lisi','男',18);
insert into employee values(3,'wangwu','女',19);
insert into employee values(4,'zhaoliu','男',15);
//分組查詢
select * from employee group by sex;
//分組查詢加條件
select * from employee group by sex having age>18;
(1) having 條件表達式:用來分組查詢后指定一些條件來輸出查詢結(jié)果
(2) having作用和where一樣践美,但having只能用于group by
多表聯(lián)查和子查詢
一對一
一張表的一條記錄一定只能與另外一張表的一條記錄進行對應(yīng)
一對多(1方建主表(id為主鍵字段), 多方建外鍵字段)
一個實體的某個數(shù)據(jù)與另外一個實體的多個數(shù)據(jù)有關(guān)聯(lián)關(guān)系, 一對多的關(guān)系在設(shè)計的時候找岖,需要設(shè)計表的外鍵陨倡。
多對多( 3個表= 2個實體表 + 1個關(guān)系表 )
一個實體的數(shù)據(jù)對應(yīng)另外一個實體的多個數(shù)據(jù),另外實體的數(shù)據(jù)也同樣對應(yīng)當前實體的多個數(shù)據(jù)许布。
連表查詢
分類:內(nèi)連接兴革、外連接、交叉連接
交叉查詢
交叉查詢蜜唾,又叫笛卡爾積查詢杂曲,會將左表和右表的信息,做一個乘積將所有信息查詢出來袁余,會產(chǎn)生臨時
表擎勘,比較占用內(nèi)存,生成的記錄數(shù)=表1數(shù)據(jù)個數(shù) X 表2數(shù)據(jù)個數(shù)
select * from customer,orders;
select * from customer cross join orders;
13.2.2 內(nèi)連接查詢
內(nèi)連接颖榜,inner join on 查詢兩張表棚饵,設(shè)定條件,將兩張表中對應(yīng)的數(shù)據(jù)查詢出來掩完,不會產(chǎn)生笛卡爾積噪漾,不會產(chǎn)生臨時表,性能高
select * from customer c inner join orders o on c.id=o.customer_id;
select * from customer,orders where customer.id=orders.customer_id;
select * from customer c,orders o where c.id=o.customer_id;
13.2.3 左外連接
左外連接 left join on 設(shè)定條件且蓬,將兩張表對應(yīng)的數(shù)據(jù)查詢出來欣硼,同時將左表自己沒有關(guān)聯(lián)的數(shù)據(jù)也查詢出來
注意:join前面是左,后面是右
select * from customer c left join orders o on c.id=o.customer_id;
13.2.4 右外連接
右外連接 right join on 設(shè)定條件缅疟,將兩張表對應(yīng)的數(shù)據(jù)查詢出來分别,同時將右表自己沒有關(guān)聯(lián)的所有數(shù)據(jù)查詢出來
select * from customer c right join orders o on c.id=o.customer_id;
練習(xí) 聯(lián)合查詢
select * from customer left join orders on customer.id=orders.customer_id having price>20;