版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、第 1 頁 province maintenance center pmc 數(shù)據(jù)庫基礎(chǔ) 4數(shù)據(jù)管理技術(shù)的發(fā)展 4數(shù)據(jù)庫(db)和數(shù)據(jù)庫管理系統(tǒng)(dbms) 4b/s、c/s架構(gòu),以及數(shù)據(jù)庫的應(yīng)用 4sql(結(jié)構(gòu)化查詢語言) 概念 4數(shù)據(jù)庫系統(tǒng)在省維護(hù)中心的應(yīng)用 第 2 頁 province maintenance center pmc 第 3 頁 province maintenance center pmc 數(shù)據(jù)庫 (database) 數(shù)據(jù)庫管理系統(tǒng) dbms 4database management system 4數(shù)據(jù)庫管理系統(tǒng)是位于用戶與操作系統(tǒng)之間的一層數(shù)據(jù)管理軟件。數(shù)據(jù)庫在建立、
2、 運(yùn)用和維護(hù)時由數(shù)據(jù)庫管理系統(tǒng)統(tǒng)一管理、統(tǒng)一控制。數(shù)據(jù)庫管理系統(tǒng)使用戶能方 便地定義數(shù)據(jù)和操縱數(shù)據(jù),并能夠保證數(shù)據(jù)的安全性、完整性、多用戶對數(shù)據(jù)的并 發(fā)使用及發(fā)生故障后的系統(tǒng)恢復(fù)。 數(shù)據(jù)庫管理員 dba 4數(shù)據(jù)庫系統(tǒng)管理員(database administrator,簡稱dba) 第 4 頁 province maintenance center pmc user 數(shù)據(jù)庫 應(yīng)用程序 dbms user 數(shù)據(jù)庫 dbms user 第 5 頁 province maintenance center pmc sql是結(jié)構(gòu)化查詢語言(structure query language)的縮寫,是關(guān)系
3、型數(shù) 據(jù)庫管理系統(tǒng)的標(biāo)準(zhǔn)語言。包括數(shù)據(jù)定義、數(shù)據(jù)操縱、數(shù)據(jù)查詢和數(shù) 據(jù)控制四個方面,共9個命令。 數(shù)據(jù)定義 4create,alter,drop 數(shù)據(jù)查詢 4select 數(shù)據(jù)操作 4insert,update,delete 數(shù)據(jù)控制 4grant,revoke 第 6 頁 province maintenance center pmc 數(shù)據(jù)庫在省維護(hù)中心的應(yīng)用 oracle 4交換網(wǎng)管,工單系統(tǒng) 4nmss,資源管理系統(tǒng)等 sql server 4mps cms wms 等web系統(tǒng) 4短信群發(fā)等系統(tǒng) 注:notes使用的是文檔數(shù)據(jù)庫,不是關(guān)系數(shù)據(jù)庫 第 7 頁 province maint
4、enance center pmc select 查詢語句 4group by 分組語句 4order by 排序語句 4join 連接語句 4into 語句 4union 合并語句 4like 語句 4sql的特殊語句 insert 插入語句 update 更新語句 delete 刪除語句 第 8 頁 province maintenance center pmc select的命令格式 select語句的一般格式為: 【命令】 select all/distinct top percent. as ,as from , inner/left/right/full join on into
5、/to file /to printer/to screen where and and/orand/or group by ,having order by asc/desc,asc/desc; 第 9 頁 province maintenance center pmc 1、用 “%”匹配多個字符 (1)a%a:可篩選:aa,aba,abbba,不能篩選:abc (2)%ab%:可篩選:abc,aabb,xab,不能篩選:azb,bac 例: 以“網(wǎng)”開頭:select * from company where name like 網(wǎng)% 以“通”結(jié)尾:select * from compan
6、y where name like %通 “四”開頭、“通”結(jié)尾:select % from company where name like 四%通 包含有“網(wǎng)通”:select * from company where name like %網(wǎng)通% 第 10 頁 province maintenance center pmc select的運(yùn)算 1、算術(shù)運(yùn)算符 ( ) 分組括號 *、/ 乘、除 +、- 加、減 算術(shù)運(yùn)算符的優(yōu)先次序為括號、乘方、乘除和加減,同級運(yùn)算從左到右依次進(jìn)行 例:還有多少年退休: select sno,sname,60-sold as tx_old from stude
7、nt 45年以后已退休的有哪些: select * from student where sold+45=60 2、關(guān)系運(yùn)算符 大于 = 等于 = 大于等于 不等于 字符的比較是按ascii碼的大小進(jìn)行的,漢字是按機(jī)內(nèi)碼比較大小的。 對于表達(dá)式則是先算表達(dá)式的值,然后用值比較大小。 select * from student where sold+45=60 第 11 頁 province maintenance center pmc select的運(yùn)算 3、邏輯運(yùn)算符 and 邏輯與 or 邏輯或 not 邏輯非 邏輯運(yùn)算符的優(yōu)先次序為:notandor 表達(dá)式的運(yùn)算順序是先關(guān)系表達(dá)式后邏輯
8、表達(dá)式 例1: select * from student where (sold+45=60 and ssex=男) or (sold+45=55 and ssex=女) 例2: select * from student where age is null / is not null 第 12 頁 province maintenance center pmc select的函數(shù) 1、avg(字段名或表達(dá)式):算數(shù)平均數(shù) select avg(sold) as avg_old from student 2、count (字段名或表達(dá)式) :計算記錄條數(shù) select count(*) as
9、 nsrs from student where ssex=女 3、sum (字段名或表達(dá)式) :返回某特定字段或是運(yùn)算的總和數(shù)值。 select sum(score) as t_score from curse where sno=870101 4、max (字段名或表達(dá)式)、 min (字段名或表達(dá)式):求最大、最小值 上述統(tǒng)計函數(shù)多與group by 聯(lián)合使用。另注意having的用法 例:統(tǒng)計出每門課的最高分 select cname,max(score) as max_score,min(score) as min_score from curse group by cname 第
10、13 頁 province maintenance center pmc select的between and 決定某一數(shù)值是否介于特定的范圍之內(nèi) 例:查詢年齡在25-30歲之間的學(xué)生 select * from student where sold between 25 and 30 等價于: select * from student where sold=25 and sold=30 第 14 頁 province maintenance center pmc select的 join union 將兩個以上的表格或是查詢的結(jié)果組合起來,但組合的兩部分內(nèi)容必須具有相 同的結(jié)構(gòu)。 例:將兩
11、個表中的男生數(shù)據(jù)提出來放在一起 select * from student1 where ssex=男 union select * from student2 where ssex=男 inner join :顯示符合條件的記錄,此為默認(rèn)值; left join:顯示符合條件的數(shù)據(jù)行以及左邊表中不符合條件的數(shù)據(jù)行, 此時右邊數(shù)據(jù)行會以null來顯示,此稱為左連接; right join:顯示符合條件的數(shù)據(jù)行以及右邊表中不符合條件的數(shù)據(jù)行, 此時左邊數(shù)據(jù)行會以null來顯示,此稱為右連接; full join:顯示符合條件的數(shù)據(jù)行以及左邊表和右邊表中不符合條件的 數(shù)據(jù)行,此時缺乏數(shù)據(jù)的數(shù)據(jù)行會
12、以null來顯示; 當(dāng)將join 關(guān)鍵詞放于from子句中時,應(yīng)有關(guān)鍵詞on與之相對應(yīng),以表明 連接的條件。 第 15 頁 province maintenance center pmc select的exists exists用于判斷子查詢結(jié)果是否存在。帶有exists的子查詢不返回任何 實際數(shù)據(jù),它只得到邏輯值“真”或“假”。當(dāng)子查詢的查詢結(jié)果集合為非 空時,外層的where子句返回真值,否則返回假值。not exists與此相反 。含有in的查詢通常可用exists表示,但反過來不一定。 例1 查詢講授課程號為“c140”的教師姓名。 select 姓名;from 教師; where e
13、xists; (select * ; from 授課; where 教師.教師號=授課.教師號 and 課程號=c140) 當(dāng)子查詢授課表存在一行記錄滿足其where子句中的條件時,則父查詢便 得到一個教師姓名,重復(fù)執(zhí)行以上過程,直到得出最后結(jié)果。 例2 刪除的時候檢驗是否有員工存在 delete from 部門 where 部門編號=19 and not exists(select * from 員工 where 員工.部門編號=部門.部門編號) 第 16 頁 province maintenance center pmc sql的inster 插入數(shù)據(jù)是把新的記錄插入到一個存在的表中。插入
14、數(shù)據(jù)使用語句insert into,可插入一條記錄,也可插入多條記錄。 1. 插入一行新記錄 【命令】 insert into (,) values(,) 【功能】 將新記錄插入到指定的表中,分別用表達(dá)式1、表達(dá)式2等為字 段名1、字段名2等賦值。 【說明】 是指要插入新記錄的表;是可選項,指定待添 加數(shù)據(jù)的列;values子句指定待添加數(shù)據(jù)的具體值。 列名的排列順序不一定要和表定義時的順序一致。但當(dāng)指定字段名時, values子句表達(dá)式的排列順序必須和字段名的排列順序一致,個數(shù)相等,數(shù) 據(jù)類型一一對應(yīng)。into語句中沒有出現(xiàn)的列名,新記錄在這些列上將取空值 (如果在表定義時說明了not nu
15、ll的屬性列不能取空值)。如果into子句沒 有帶任何列名,則插入的新記錄必須在每個屬性列上均有值。 第 17 頁 province maintenance center pmc sql的select 1. 從第2表中將數(shù)據(jù)插入 【命令】 insert into (,) (select (, from 源表 where ) 例:例: insert into bestuser (insert into bestuser (姓名姓名, ,工號工號, ,績效得分績效得分, ,公司名公司名, ,金額金額, ,年度年度) ) selectselect姓名姓名, ,工號工號, ,績效得分績效得分,四川網(wǎng)通
16、四川網(wǎng)通 as as公司名公司名,100 as ,100 as 金額金額, ,年度年度 from from 績效表績效表 where where 績效得分績效得分9090 將績效得分大于將績效得分大于9090的加入到優(yōu)秀員工表里面的加入到優(yōu)秀員工表里面 第 18 頁 province maintenance center pmc sql的update sql語言可以使用update語句對表中的一行或多行記錄的某些列值進(jìn)行 修改。 【命令】 update set = ,= where 【功能】 對表中的一行或多行記錄的某些列值進(jìn)行修改。 【說明】 是指要修改的表;set子句給出要修改的列及其修改
17、后 的值;where子句指定待修改的記錄應(yīng)當(dāng)滿足的條件,where子句省略時,則 修改表中的所有記錄。 修改一行記錄 把“陳靜”教師的職稱改成副教授。 update 教師; set 職稱=副教授; where 姓名=陳 靜 第 19 頁 province maintenance center pmc sql的update from 從第二表取數(shù)據(jù)來更新第一表從第二表取數(shù)據(jù)來更新第一表 更新用戶數(shù)據(jù)的地區(qū)信息更新用戶數(shù)據(jù)的地區(qū)信息 update update 用戶數(shù)據(jù)用戶數(shù)據(jù) setset 地區(qū)地區(qū)=(=(selectselect 地區(qū)地區(qū) fromfrom 地區(qū)表地區(qū)表 where where
18、 用用 戶數(shù)據(jù)戶數(shù)據(jù). .區(qū)號區(qū)號= =地區(qū)表地區(qū)表. .區(qū)號區(qū)號 ) ) wherewhere 地區(qū)地區(qū) is nullis null 多數(shù)據(jù)更新多數(shù)據(jù)更新 updateupdate 用戶數(shù)據(jù)用戶數(shù)據(jù) setset 地區(qū)地區(qū)= =地區(qū)表地區(qū)表. .地區(qū)地區(qū), ,省份省份= =地區(qū)表地區(qū)表. .省份省份 fromfrom 地區(qū)表地區(qū)表 wherewhere 用戶數(shù)據(jù)用戶數(shù)據(jù). .區(qū)號區(qū)號= =地區(qū)表地區(qū)表. .區(qū)號區(qū)號 andand ( (用戶數(shù)據(jù)用戶數(shù)據(jù). .地區(qū)地區(qū) is null is null or or 用戶數(shù)據(jù)用戶數(shù)據(jù). .省份省份is null )is null ) 第 20 頁 province maintenance center pmc select的delete 刪除指定數(shù)據(jù)。 delete from where 例:從名單中刪除王五 delete from student where sname= 王五 該語句將刪除學(xué)生表中所有姓名為王五的記錄 注意: d
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 馬戲團(tuán)合作協(xié)議書
- 2025年個人別墅測繪項目合同范本
- 2025版房地產(chǎn)開發(fā)項目施工合同交底書范本2篇
- 2025-2030全球三氟化銪行業(yè)調(diào)研及趨勢分析報告
- 2025-2030全球高折射率光纖行業(yè)調(diào)研及趨勢分析報告
- 2025-2030全球滑動軸承襯套行業(yè)調(diào)研及趨勢分析報告
- 2025-2030全球落地護(hù)眼燈行業(yè)調(diào)研及趨勢分析報告
- 2025年全球及中國微膠囊熱致變色顏料行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 石料破碎加工合同范本
- 2025版?zhèn)€人股權(quán)交易保密協(xié)議書4篇
- 中國末端執(zhí)行器(靈巧手)行業(yè)市場發(fā)展態(tài)勢及前景戰(zhàn)略研判報告
- 北京離婚協(xié)議書(2篇)(2篇)
- 2025中國聯(lián)通北京市分公司春季校園招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
- 康復(fù)醫(yī)學(xué)科患者隱私保護(hù)制度
- Samsung三星SMARTCAMERANX2000(20-50mm)中文說明書200
- 2024年藥品質(zhì)量信息管理制度(2篇)
- 2024年安徽省高考地理試卷真題(含答案逐題解析)
- 廣東省廣州市2024年中考數(shù)學(xué)真題試卷(含答案)
- 高中學(xué)校開學(xué)典禮方案
- 內(nèi)審檢查表完整版本
- 3級人工智能訓(xùn)練師(高級)國家職業(yè)技能鑒定考試題及答案
評論
0/150
提交評論