![高級(jí)數(shù)據(jù)庫(kù)技術(shù)PPT課件_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/20/585ed409-f458-4f0e-a5c1-3a4f6e37e964/585ed409-f458-4f0e-a5c1-3a4f6e37e9641.gif)
![高級(jí)數(shù)據(jù)庫(kù)技術(shù)PPT課件_第2頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/20/585ed409-f458-4f0e-a5c1-3a4f6e37e964/585ed409-f458-4f0e-a5c1-3a4f6e37e9642.gif)
![高級(jí)數(shù)據(jù)庫(kù)技術(shù)PPT課件_第3頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/20/585ed409-f458-4f0e-a5c1-3a4f6e37e964/585ed409-f458-4f0e-a5c1-3a4f6e37e9643.gif)
![高級(jí)數(shù)據(jù)庫(kù)技術(shù)PPT課件_第4頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/20/585ed409-f458-4f0e-a5c1-3a4f6e37e964/585ed409-f458-4f0e-a5c1-3a4f6e37e9644.gif)
![高級(jí)數(shù)據(jù)庫(kù)技術(shù)PPT課件_第5頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2021-12/20/585ed409-f458-4f0e-a5c1-3a4f6e37e964/585ed409-f458-4f0e-a5c1-3a4f6e37e9645.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、高級(jí)數(shù)據(jù)庫(kù)技術(shù)高級(jí)數(shù)據(jù)庫(kù)技術(shù)2020年秋季年秋季Chapter MORE SQL: Assertions, Views, and Programming TechniquesChapter Outline9.1 General Constraints as Assertions9.2 Views in SQL9.3 Database Programming9.4 Embedded SQL9.5 Functions Calls, SQL/CLI9.6 Stored Procedures, SQL/PSM9.7 SummaryChapter ObjectiveslSpecification of
2、more general constraints via assertionslSQL facilities for defining views (virtual tables)lVarious techniques for accessing and manipulating a database via programs in general-purpose languages (e.g., Java)Constraints as Assertionsl General constraints: constraints that do not fit in the basic SQL c
3、ategories (presented in chapter 8)l Mechanism: CREAT ASSERTIONcomponents include: a constraint name, followed by CHECK, followed by a conditionAssertions: An Examplel“The salary of an employee must not be greater than the salary of the manager of the department that the employee works forCREAT ASSER
4、TION SALARY_CONSTRAINTCHECK (NOT EXISTS (SELECT * FROM EMPLOYEE E, EMPLOYEE M, DEPARTMENT D WHERE E.SALARY M.SALARY AND E.DNO=D.NUMBER AND D.MGRSSN=M.SSN)Using General AssertionslSpecify a query that violates the condition; include inside a NOT EXISTS clauselQuery result must be empty if the query r
5、esult is not empty, the assertion has been violatedSQL TriggerslObjective: to monitor a database and take action when a condition occurslTriggers are expressed in a syntax similar to assertions and include the following: event (e.g., an update operation) condition action (to be taken when the condit
6、ion is satisfied)SQL Triggers: An Examplel A trigger to compare an employees salary to his/her supervisor during insert or update operations:CREATE TRIGGER INFORM_SUPERVISORBEFORE INSERT OR UPDATE OFSALARY, SUPERVISOR_SSN ON EMPLOYEEFOR EACH ROWWHEN(NEW.SALARY (SELECT SALARY FROM EMPLOYEE WHERE SSN=
7、NEW.SUPERVISOR_SSN)INFORM_SUPERVISOR (NEW.SUPERVISOR_SSN,NEW.SSN;Views in SQLlA view is a “virtual” table that is derived from other tableslAllows for limited update operations (since the table may not physically be stored)lAllows full query operationslA convenience for expressing certain operations
8、Specification of Viewsl SQL command: CREATE VIEW a table (view) name a possible list of attribute names (for example, when arithmetic operations are specified or when we want the names to be different from the attributes in the base relations) a query to specify the table contentsSQL Views: An Examp
9、lelSpecify a different WORKS_ON tableCREATE TABLE WORKS_ON_NEW ASSELECT FNAME, LNAME, PNAME, HOURSFROM EMPLOYEE, PROJECT, WORKS_ON WHERE SSN=ESSN AND PNO=PNUMBERGROUP BY PNAME;Using a Virtual TablelWe can specify SQL queries on a newly create table (view):SELECT FNAME, LNAME FROM WORKS_ON_NEWWHERE P
10、NAME=Seena;lWhen no longer needed, a view can be dropped:DROP WORKS_ON_NEW;Efficient View ImplementationlQuery modification: present the view query in terms of a query on the underlying base tables disadvantage: inefficient for views defined via complex queries (especially if additional queries are
11、to be applied to the view within a short time period)Efficient View ImplementationlView materialization: involves physically creating and keeping a temporary table assumption: other queries on the view will follow concerns: maintaining correspondence between the base table and the view when the base
12、 table is updated strategy: incremental updateView UpdatelUpdate on a single view without aggregate operations: update may map to an update on the underlying base tablelViews involving joins: an update may map to an update on the underlying base relations not always possibleUn-updatable ViewslViews
13、defined using groups and aggregate functions are not updateablelViews defined on multiple tables using joins are generally not updateablel WITH CHECK OPTION: must be added to the definition of a view if the view is to be updated to allow check for updatability and to plan for an execution strategyDa
14、tabase ProgramminglObjective: to access a database from an application program (as opposed to interactive interfaces)lWhy? An interactive interface is convenient but not sufficient; a majority of database operations are made thru application programs (nowadays thru web applications)Database Programm
15、ing ApproacheslEmbedded commands: database commands are embedded in a general-purpose programming languagelLibrary of database functions: available to the host language for database calls; known as an APIlA brand new, full-fledged language (minimizes impedance mismatch)Impedance MismatchlIncompatibi
16、lities between a host programming language and the database model, e.g., type mismatch and incompatibilities; requires a new binding for each language set vs. record-at-a-time processinglneed special iterators to loop over query results and manipulate individual valuesSteps in Database Programming1.
17、 Client program opens a connection to the database server2. Client program submits queries to and/or updates the database3. When database access is no longer needed, client program terminates the connectionEmbedded SQLlMost SQL statements can be embedded in a general-purpose host programming languag
18、e such as COBOL, C, JavalAn embedded SQL statement is distinguished from the host language statements by EXEC SQL and a matching END-EXEC (or semicolon) shared variables (used in both languages) usually prefixed with a colon (:) in SQLExample: Variable Declarationin Language Cl Variables inside DECL
19、ARE are shared and can appear (while prefixed by a colon) in SQL statementsl SQLCODE is used to communicate errors/exceptions between the database and the programint loop;EXEC SQL BEGIN DECLARE SECTION;varchar dname16, fname16, ;char ssn10, bdate11, ;int dno, dnumber, SQLCODE, ;EXEC SQL END DECLARE
20、SECTION;SQL Commands forConnecting to a DatabaselConnection (multiple connections are possible but only one is active)CONNECT TO server-name AS connection-nameAUTHORIZATION user-account-info;lChange from an active connection to another oneSET CONNECTION connection-name;lDisconnectionDISCONNECT conne
21、ction-name; Embedded SQL in CProgramming Examplesloop = 1;while (loop) prompt (“Enter SSN: “, ssn);EXEC SQLselect FNAME, LNAME, ADDRESS, SALARYinto :fname, :lname, :address, :salaryfrom EMPLOYEE where SSN = :ssn;if (SQLCODE = 0) printf(fname, );else printf(“SSN does not exist: “, ssn);prompt(“More S
22、SN? (1=yes, 0=no): “, loop);END-EXEC Embedded SQL in CProgramming ExampleslA cursor (iterator) is needed to process multiple tupleslFETCH commands move the cursor to the next tuplelCLOSE CURSOR indicates that the processing of query results has been completedDynamic SQLl Objective: executing new (no
23、t previously compiled) SQL statements at run-time a program accepts SQL statements from the keyboard at run-time a point-and-click operation translates to certain SQL queryl Dynamic update is relatively simple; dynamic query can be complex because the type and number of retrieved attributes are unkn
24、own at compile timeDynamic SQL: An ExampleEXEC SQL BEGIN DECLARE SECTION;varchar sqlupdatestring256;EXEC SQL END DECLARE SECTION;prompt (“Enter update command:“, sqlupdatestring);EXEC SQL PREPARE sqlcommand FROM :sqlupdatestring;EXEC SQL EXECUTE sqlcommand;Embedded SQL in JavalSQLJ: a standard for e
25、mbedding SQL in JavalAn SQLJ translator converts SQL statements into Java (to be executed thru the JDBC interface)lCertain classes, e.g., java.sql have to be importedJava Database ConnectivitylJDBC: SQL connection function calls for Java programminglA Java program with JDBC functions can access any
26、relational DBMS that has a JDBC driverlJDBC allows a program to connect to several databases (known as data sources)Steps in JDBC Database Access1. Import JDBC library (java.sql.*)2. Load JDBC driver: Class.forname(“oracle.jdbc.driver.OracleDriver”)3. Define appropriate variables4. Create a connect object (via getConnection)5. Create a statement object from the Statement class:1.PreparedStatment2.CallableStatementSteps in JDBC Database Access(continued)6. Identify statement parameters (to be designated by question marks)7. Bound parameters to pr
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 岸坡拋石工程施工方案
- 環(huán)保技術(shù)引領(lǐng)未來(lái)環(huán)境科學(xué)與城市發(fā)展
- 中小學(xué)生欺凌專(zhuān)項(xiàng)治理行動(dòng)方案
- 現(xiàn)代通信技術(shù)在教育領(lǐng)域的應(yīng)用
- 2024年四年級(jí)英語(yǔ)上冊(cè) Module 5 Unit 2 Can Sam play football說(shuō)課稿 外研版(三起)001
- 2024八年級(jí)英語(yǔ)下冊(cè) Unit 2 Plant a PlantLesson 7 Planting Trees說(shuō)課稿(新版)冀教版
- 2024新教材高中政治 第二單元 經(jīng)濟(jì)發(fā)展與社會(huì)進(jìn)步 第四課 我國(guó)的個(gè)人收入分配與社會(huì)保障 4.1《我國(guó)的個(gè)人收入分配》說(shuō)課稿 部編版必修2
- Module4 Unit1 Mum bought a new T-shirt for me(說(shuō)課稿)-2024-2025學(xué)年外研版(三起)英語(yǔ)五年級(jí)上冊(cè)
- 《6 蛋殼與薄殼結(jié)構(gòu)》(說(shuō)課稿)-2023-2024學(xué)年五年級(jí)下冊(cè)科學(xué)蘇教版
- 2025北京市勞務(wù)分包合同范本問(wèn)題范本
- 2025-2030年中國(guó)反滲透膜行業(yè)市場(chǎng)發(fā)展趨勢(shì)展望與投資策略分析報(bào)告
- 湖北省十堰市城區(qū)2024-2025學(xué)年九年級(jí)上學(xué)期期末質(zhì)量檢測(cè)道德與法治試題 (含答案)
- 山東省濰坊市2024-2025學(xué)年高三上學(xué)期1月期末 英語(yǔ)試題
- 春節(jié)節(jié)后收心會(huì)
- 《榜樣9》觀后感心得體會(huì)四
- 七年級(jí)下冊(cè)英語(yǔ)單詞表(人教版)-418個(gè)
- 交警安全進(jìn)校園課件
- (2024年高考真題)2024年普通高等學(xué)校招生全國(guó)統(tǒng)一考試數(shù)學(xué)試卷-新課標(biāo)Ⅰ卷(含部分解析)
- HCIA-AI H13-311 v3.5認(rèn)證考試題庫(kù)(含答案)
- 潤(rùn)滑油過(guò)濾培訓(xùn)
- 內(nèi)蒙自治區(qū)烏蘭察布市集寧二中2025屆高考語(yǔ)文全真模擬密押卷含解析
評(píng)論
0/150
提交評(píng)論