




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Chapter 7Chapter 7Chapter 7Chapter 7Chapter 7Chapter 7Chapter 7Figure 7-1A simplified schematic of a typical SQL environment, as described by the SQL: 200n standard實(shí)務(wù)上或稱為實(shí)務(wù)上或稱為DB SpaceChapter 7註:資料型別可能各家廠商略有不同或自有擴(kuò)充註:資料型別可能各家廠商略有不同或自有擴(kuò)充Chapter 7Figure 7-4 DDL, DML, DCL, and the database development p
2、rocess必會(huì)必會(huì)CREATE TABLEALTER TABLEDROP TABLE必會(huì)必會(huì)INSERTDELETEUPDATESELECTChapter 7Chapter 7Figure 7-5 General syntax for CREATE TABLESteps in table creation:1.Identify data types for attributes2.Identify columns that can and cannot be null3.Identify columns that must be unique (candidate keys)4.Identi
3、fy primary keyforeign key mates5.Determine default values6.Identify constraints on columns (domain specifications)7.Create the table and associated indexes語法表示語法表示 表選項(xiàng)表選項(xiàng), 可填可不填可填可不填 表多選表多選, 多個(gè)選一個(gè)多個(gè)選一個(gè)Chapter 7Chapter 7Figure 7-6 SQL database definition commands for Pine Valley FurnitureOverall tabl
4、e definitionsChapter 7Defining attributes and their data typesdecimal (p, s) 和和 numeric (p , s) p 固定有效位數(shù),小數(shù)點(diǎn)左右兩側(cè)都包括在內(nèi)固定有效位數(shù),小數(shù)點(diǎn)左右兩側(cè)都包括在內(nèi) s 小數(shù)位數(shù)的數(shù)字。小數(shù)位數(shù)的數(shù)字。 numeric 與與 decimal 的功能相同。的功能相同。為為 key 取一個(gè)名字取一個(gè)名字語法參考 http:/ 7Non-nullable specificationIdentifying primary keyPrimary keys can never have NULL v
5、aluesChapter 7Non-nullable specificationsPrimary keySome primary keys are composite composed of multiple attributes注意PK為複合欄位時(shí)的寫法為為 key 取一個(gè)名字取一個(gè)名字Chapter 7Default value 指定預(yù)設(shè)值指定預(yù)設(shè)值Domain constraint指定合法值域指定合法值域Controlling the values in attributesChapter 7Primary key of parent tableIdentifying foreign k
6、eys and establishing relationshipsForeign key of dependent tableChapter 7Chapter 7Relational integrity is enforced via the primary-key to foreign-key matchFigure 7-7 Ensuring data integrity through updates1234自動(dòng)檢查完整性自動(dòng)檢查完整性有四種指定方法有四種指定方法注意注意 : 有些較簡(jiǎn)單的有些較簡(jiǎn)單的RDBMS可能不支援可能不支援Chapter 7Chapter 7Chapter 7Ch
7、apter 7New with SQL:2003自動(dòng)編號(hào)欄位型別自動(dòng)編號(hào)欄位型別加入資料時(shí)不需指定該欄位之值加入資料時(shí)不需指定該欄位之值Chapter 7Chapter 7Chapter 7Makes it easier to update a tableallows combination of Insert and Update in one statement 有點(diǎn)結(jié)合Insert與Update的意思Useful for updating master tables with new dataChapter 7Chapter 7Figure 7-10 SQL statement proc
8、essing order (adapted from van der Lans, p.100)內(nèi)部?jī)?nèi)部RDBMS在解釋在解釋這句命令時(shí)的處理順序這句命令時(shí)的處理順序Chapter 7Table 7-3: Comparison Operators in SQLChapter 7取個(gè)別名取個(gè)別名, 比較方便指定比較方便指定, 也可省去重複打字也可省去重複打字原句原句使用使用別名別名Chapter 7Chapter 7Note: the LIKE operator allows you to compare strings using wildcards. For example, the % wi
9、ldcard in %Desk indicates that all strings that have any number of characters preceding the word “Desk” will be allowedLIKE 是做字串比對(duì)用的是做字串比對(duì)用的, 支援萬用字元支援萬用字元%或或_ (類似類似Windows的的*與與?)Chapter 7集合圖集合圖Chapter 7Note: the IN operator in this example allows you to include rows whose STATE value is either FL, T
10、X, CA, or HI. It is more efficient than separate OR conditions 跟寫 STATE=FL OR STATE=TX OR 是一樣的效果ORDER BY field1 ASC|DESC ,field2 ASC|DESC可用可用ASC或或DESC來指定升冪或降冪排列來指定升冪或降冪排列Chapter 7Chapter 7原始原始表格表格SELECT area, count(*)FROM memberGROUP BY area;SELECT gender, count(*)FROM memberGROUP BY gender;Chapter
11、7原始原始表格表格SELECT gender, education, count(*) AS pplFROM memberGROUP BY gender, education;Chapter 7原始原始表格表格SELECT gender, education, count(*) AS pplFROM memberGROUP BY gender, educationORDER BY count(*) DESC;Chapter 7原始原始表格表格SELECT gender, education, count(*) AS ppl,max(age)FROM memberGROUP BY gender,
12、 education;使用不同的函數(shù)使用不同的函數(shù)Chapter 7Like a WHERE clause, but it operates on groups (categories), not on individual rows. Here, only those groups with total numbers greater than 1 will be included in final resultChapter 7SELECT gender, education, count(*) AS pplFROM memberGROUP BY gender, educationHAVING education=大學(xué)大學(xué);SELECT gender, education, count(*) AS pplFROM memberGROUP BY gender, education;HAVING可以想成是可以想成是GROUP BY後的後的WHEREChapter 7Chapter 7View has a nameVie
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)院管理會(huì)議紀(jì)要撰寫范文
- 民族團(tuán)結(jié)在藝術(shù)創(chuàng)作中的實(shí)踐工作計(jì)劃
- 小學(xué)一年級(jí)語文節(jié)慶主題教學(xué)計(jì)劃
- 應(yīng)用心理學(xué)在企業(yè)管理中的實(shí)習(xí)報(bào)告范文
- 普通高中生涯規(guī)劃與心理健康教育心得體會(huì)
- 產(chǎn)品質(zhì)量管理策略與實(shí)踐
- 藝術(shù)展覽策劃質(zhì)量管理與創(chuàng)優(yōu)計(jì)劃
- 物流行業(yè)員工心理健康支持方案
- 中小企業(yè)戰(zhàn)略規(guī)劃與實(shí)施路徑
- 企業(yè)國(guó)際化經(jīng)營(yíng)的路徑選擇與風(fēng)險(xiǎn)控制
- 2024重組膠原蛋白行業(yè)白皮書
- 【MOOC】壓力與情緒管理-四川大學(xué) 中國(guó)大學(xué)慕課MOOC答案
- 我的家鄉(xiāng)西藏山南
- 零星維修工程 投標(biāo)方案(技術(shù)方案)
- 項(xiàng)目管理培訓(xùn)之進(jìn)度管理課件
- 110kV@@變電站工程高大模板工程專項(xiàng)施工方案
- 先兆流產(chǎn)課件-課件
- 2022年北京市公務(wù)員錄用考試《行測(cè)》真題及答案解析
- DB11T 1028-2021 民用建筑節(jié)能門窗工程技術(shù)標(biāo)準(zhǔn)
- 院前急救課件教學(xué)課件
- 刑事案件會(huì)見筆錄(偵查階段)
評(píng)論
0/150
提交評(píng)論