數(shù)據(jù)庫字面意思就是裝數(shù)據(jù)的倉庫
為什么要用數(shù)據(jù)庫呢懦窘?
1.不用數(shù)據(jù)庫前翎,放在集合中的數(shù)據(jù)關(guān)閉程序后數(shù)據(jù)會丟失
2.數(shù)據(jù)放在文件中,調(diào)用時畅涂,會調(diào)用所有數(shù)據(jù)港华,占用內(nèi)存大,讀取數(shù)據(jù)不方便
數(shù)據(jù)庫就是用來管理數(shù)據(jù)的
數(shù)據(jù)庫底層午衰,數(shù)據(jù)最終存在文件中
數(shù)據(jù)庫為了能夠在網(wǎng)絡(luò)中使用立宜,所以分成兩部分,一部分是服務(wù)端臊岸,一部分是客戶端橙数。
在生產(chǎn)環(huán)境,服務(wù)端和客戶端很可能不在一臺主機
數(shù)據(jù)庫通過Socket交換數(shù)據(jù)扇单。
常用的數(shù)據(jù)庫有: mysql (免費的)(開源的)oracle(收費)(不開源)
數(shù)據(jù)庫用什么操作商模?
SQL:結(jié)構(gòu)化查詢語言:structured query language
兩個數(shù)據(jù)庫通用,但是不同的數(shù)據(jù)庫可能會有一些區(qū)別
SQL語言按功能分為四類:
DQL:數(shù)據(jù)查詢語言
DDL:數(shù)據(jù)定義語言
DML:數(shù)據(jù)操作語言
TCL:事務(wù)控制語言
對數(shù)據(jù)的增刪改查:CRUD
create? :增
Retreive? :查
Update? :更新
Delete? :刪
數(shù)據(jù)庫的查詢
select 查詢的內(nèi)容? from 表
select 1+2
select * from books
查詢出來的結(jié)果也是以表格的形式呈現(xiàn)的蜘澜,但是沒有這張表
select? id施流,name,price form books? where
為查詢結(jié)果的列去一個別名 鄙信,as可以省略
select id“book id”,name
進行記錄的篩選? ? 可以使用 >? <? >=? <=? != 可以使用and連接表示范圍
select id瞪醋,name,stock from books where id = 10
and表示和? or表示或
select id装诡,name银受,stock from books where id > 5 and stork <50
select id践盼,name,stock from books where id > 5 or stork <50
顯示作者為空的
select * from books where author is null
顯示作者不為空的
select * from books where author is not null
sql語句的格式
select
? ? ? ? id,name,stock,price
from
????????books
where
????????id>5
%代表若干字符 _代表一個字符