數(shù)據庫技術(SQL語言)課件_第1頁
數(shù)據庫技術(SQL語言)課件_第2頁
數(shù)據庫技術(SQL語言)課件_第3頁
數(shù)據庫技術(SQL語言)課件_第4頁
數(shù)據庫技術(SQL語言)課件_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

數(shù)據庫技術第5講SQL語言

數(shù)據DBMSClient請求回答SQL語言Oracle8i/9iSQLServer2000PowerBuilderVBDelphiC++Builder數(shù)據庫技術第5講SQL語言數(shù)據DBMSClient1SQLServer2000簡介

2000年2月Microsoft公司發(fā)布了Windows2000操作系統(tǒng)家族。

Windows2000ProfessionalWindows2000ServerWindows2000AdvancedServerWindows2000DatacenterServerSQLServer2000客戶端軟件SQLServer2000個人版SQLServer2000標準版SQLServer2000企業(yè)版SQLServer2000簡介2如何使用SQLServer2000?1、利用企業(yè)管理器(EnterpriseManager)建立數(shù)據庫、用戶,并且對用戶授權;2、利用查詢分析器(QueryAnalyzer)對SQLServer進行查詢、管理。如何使用SQLServer2000?131、SQL語言概述SQL(StructuredQuerylanguage)語言是1974年由Boyce和Chamberlin提出的。1975年~1979年IBM公司SanJoseResearchLaboratory研制了著名的關系數(shù)據庫管理系統(tǒng)原型SystemR,并實現(xiàn)了這種語言。由于它功能豐富、語言簡捷,倍受用戶及計算機工業(yè)界歡迎,被眾多計算機公司和軟件公司所采用。經各公司的不斷修改、擴充和完善,SQL語言最終發(fā)展成為關系數(shù)據庫的標準語言。1、SQL語言概述41986年10月美國國家標準局(AmericanNationalStandardInstitute,簡稱ANSI)的數(shù)據庫委員會X3H2批準了SQL作為關系數(shù)據庫語言的美國標準。同年公布了SQL標準文本(簡稱SQL-86)。1987年國際標準化組織(InternationalOrganizationforstandardization,簡稱ISO)也通過了這一標準。此后ANSI不斷修改和完善SQL標準,并于1989年公布了SQL-89標準。1992年又公布了SQL-92標準。1999年又公布了SQL-99標準。1986年10月美國國家標準局(Americ5SQL-99是SQL-92的一個超集。許多數(shù)據庫系統(tǒng)支持SQL-99的新結構,但目前還沒有一個數(shù)據庫系統(tǒng)完全支持SQL-99的所有新結構。實際上甚至目前的數(shù)據庫系統(tǒng)不能完全支持SQL-92。SQL-99是SQL-92的一個超集。許多數(shù)6自SQL成為國際標準語言以后,各個數(shù)據庫廠家紛紛推出各自的SQL軟件或與SQL的接口軟件。這就使大多數(shù)數(shù)據庫系統(tǒng)均用SQL作為共同的數(shù)據存取語言和標準接口,使不同數(shù)據庫系統(tǒng)之間的互操作有了共同的基礎。這個意義十分重大。因此,有人把確立SQL為關系數(shù)據庫語言標準及其后的發(fā)展稱為是一場革命。自SQL成為國際標準語言以后,各個數(shù)據庫廠家7SQL成為國際標準,對數(shù)據庫以外的領域也產生了很大影響,有不少軟件產品將SQL語言的數(shù)據查詢功能與圖形功能、軟件工程工具、軟件開發(fā)工具、人工智能程序結合起來。SQL已成為數(shù)據庫領域中一個主流語言。SQL成為國際標準,對數(shù)據庫以外的領域也產生82、SQL語言的特點集DDL、DML、DCL于一體;高度非過程化;面向集合的操作方式;一種語法提供兩種操作方式(交互式、嵌入式)。2、SQL語言的特點9嵌入式SQLSQL是一種強有力的聲明性查詢語言,它在許多情況下比通用編程語言的編碼簡單許多。但是使用通用編程語言(至少具有過程化語言的特性)訪問數(shù)據庫還是很必要的,原因有二:1、SQL不能表達所有查詢要求。2、非聲明性的動作(例如,打印一份報告或把一次查詢結果送到一個圖形用戶界面中)都不能用SQL實現(xiàn)。嵌入式SQL10動態(tài)SQL

SQL的動態(tài)SQL組件允許程序在運行時構造、提交SQL查詢。使用動態(tài)SQL,程序可以在運行時以字符串的形式生成SQL查詢。動態(tài)SQL11數(shù)據類型(SQL-92)char(n):固定長度的字符串。varchar(n):可變長字符串。int:整數(shù)。smallint:小整數(shù)類型。numeric(p,d):定點數(shù),精度p位,小數(shù)點右邊d位。real:浮點數(shù)。doubleprecision:雙精度浮點數(shù)。date:日期(年、月、日)。time:時間(小時、分、秒)。interval:兩個date或time類型數(shù)據之間的差。數(shù)據類型(SQL-92)12注意:目前各公司都在自己的DBMS上實現(xiàn)了對SQL語言的支持,但在語言的功能上都根據實際需要進行了擴充或簡化。特別是,都增加了對過程化語句的支持功能。例如,Oracle所支持的是PL/SQLSQLServer2000支持的是Transact-SQL注意:目前各公司都在自己的DBMS上實現(xiàn)了對SQL語言的支持133、SQL語言的三級模式SQLViewTableTableTableDatafile3、SQL語言的三級模式SQLViewTableTableT144、SQL語言數(shù)據定義(DDL)CreatetableDroptableCreateViewDropViewCreateIndexDropIndex數(shù)據操縱(DML)SelectUpdateInsertDelete數(shù)據控制(DCL)GrantRevoke4、SQL語言15SQL語言舉例createtableTeacher(TnointegerPrimaryKey,Tnamechar(6)notnull,Titlechar(6),Deptchar(10));insertintoTeachervalues(101,‘李華’,‘講師’,‘計算機’);insertintoTeacher(Tno,Tname,Dept)values(104,'李春生','計算機');SQL語言舉例insertintoTeacher16select*fromteacherwheredept='通信';selectTname,Deptfromteacherwheredept=‘通信’;select*fromteacherwheredept=‘通信’andTitle=‘講師’;updateteachersetdept='通信工程'wheredept='通信';deletefromteacherwheredept='計算機';createtableTeacher(TnointegerPrimaryKey,Tnamechar(6)notnull,Titlechar(6),Deptchar(10));select*fromteacherupdatete17createTableCourse(Cnointegernotnull,Tnointegernotnull,Cnamechar(10)notnull,creditnumeric(3,1)notnull,Primarykey(cno,tno));insertintoCoursevalues(1,101,‘數(shù)據庫’,3.5);insertintoCoursevalues(1,103,'數(shù)據庫',3.5);insertintoCoursevalues(2,102,'網絡',3);insertintoCoursevalues(2,101,'網絡',3);insertintoCoursevalues(3,103,‘操作系統(tǒng)’,3);createTableCourse(insertint18selectdistinctcnamefromcourse;select*fromcoursewherecredit>3;select*fromcoursewherecreditbetween2and3;createTableCourse(Cnointegernotnull,Tnointegernotnull,Cnamechar(10)notnull,creditnumeric(3,1)notnull,Primarykey(cno,tno));selectdistinctcnamefromcou19select*fromteacherwheredeptin('計算機','自動化');select*fromteacherwheredeptnotin('計算機');select*fromteacherwheretnamelike'李%';select*fromteacherwheretitleisnull;select*fromteacherorderbytnodesc;select*fromteacherorderbytitle;selectcount(*)fromteacher;selectcount(distinctcname)fromcourse;select*fromteacherwherede20數(shù)據庫技術第6講SQL語言(二)

數(shù)據DBMSClient請求回答SQL語言Oracle8i/9iSQLServer2000PowerBuilderVBDelphiC++Builder數(shù)據庫技術第6講SQL語言(二)數(shù)據DBMSCli21createTableCourse(Cnointegernotnull,Tnointegernotnull,Cnamechar(10)notnull,creditnumeric(3,1)notnull,Primarykey(cno,tno));createtableTeacher(TnointegerPrimaryKey,Tnamechar(6)notnull,Titlechar(6),Deptchar(10));select*fromteacher,course;select*fromteacher,coursewhereteacher.tno=course.tno;createTableCourse(createtab22selectcname,creditfromcoursewhereTnoin(selectTnofromTeacherwhereTname='李華');selectcname,creditfromteacher,coursewhere(teacher.tno=course.tno)andTname='李華';查詢李華所授課程的名稱,學分selectcname,creditfromcours23selectcname,creditfromcoursewhereTnoin(selectTnofromTeacherwhereTitle='講師');selectcname,creditfromteacher,coursewhere(teacher.tno=course.tno)andTitle='講師';selectcname,creditfromcours24視圖(View)createviewv_t_casselectTeacher.Tno,Tname,Title,Dept,Cno,CnamefromTeacher,coursewhereTeacher.Tno=course.Tno;Select*fromv_t_c;Select*fromv_t_cwhereTno=101;視圖(View)25索引createTableCourse(Cnointegernotnull,Tnointegernotnull,Cnamechar(10)notnull,creditnumeric(3,1)notnull);createuniqueindexcourse_indoncourse(Tno,Cno);createTableCourse(Cnointegernotnull,Tnointegernotnull,Cnamechar(10)notnull,creditnumeric(3,1)notnull,Primarykey(cno,tno));索引createTableCourse(26Groupby和Having子句createtableTeacher(TnointegerPrimaryKey,Tnamechar(6)notnull,Titlechar(6),Deptchar(10));select*fromteacher;selecttitle,count(*)fromteachergroupbytitle;selecttitle,count(*)fromteachergroupbytitlehavingcount(*)>1;Groupby和Having子句createtab27認識nullinsertintoTeachervalues(903,'劉力偉','助教','計算機');insertintoTeachervalues(904,‘趙鶯’,null,‘計算機’);insertintoTeachervalues(905,'張大軍',null,null);createtableTeacher(TnointegerPrimaryKey,Tnamechar(6)notnull,Titlechar(6),Deptchar(10));認識nullcreatetableTeacher(28外鍵createtablefather_t(Cnointegerprimarykey,Cnamechar(10)notnull,Creditnumeric(3,1));createtableson_t(st_nointegerprimarykey,

fk_cnointeger,gradeinteger,foreignkey(fk_cno)referencesfather_t(Cno));insertintofather_tvalues(1,'數(shù)據庫',2);insertintofather_tvalues(2,'網絡',3);insertintoson_tvalues(101,2,86);insertintoson_tvalues(102,5,78);外鍵createtableson_tinsertint29授權GrantselectonTeachertost2;R

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論