2013 Fall 1 Chapter 8: Advanced SQL 楊立偉教授 台灣大學工管系 註 : 於 11 版為 Chapter 7.

Slides:



Advertisements
Similar presentations
Advanced SQL (part 1) CS263 Lecture 7.
Advertisements

© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
Installment 7 Tables With No Column Presented by rexmen 2001 資管所.林彥廷.
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
3Com Switch 4500 切VLAN教學.
BY OX. 檢視表與資料表的差異性 查詢 (query) 檢視表 (View) 的紀錄,是經由查詢 (query) 而來,而檢 視表的資料來源可以是單一資料表或是多資料表,甚 至其他檢視表 但檢視表中的紀錄只存在資料表中.
1 Web of Science 利用指引 單元二 瀏覽與處理查詢結果. 2 瀏覽檢索結果 查出的結果,預設以時間排列, 使用者可改變結果的排列方式: 還可以依被引用次數、相關度、 第一作者、刊名、出版年等排序 回到前先查的結果畫面 點選想看資料的完整書目 本館訂購範圍的期刊 全文,便可直接連結.
亂數產生器安全性評估 之統計測試 SEC HW7 姓名:翁玉芬 學號:
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
© 2007 by Prentice Hall 1 Chapter 8: Advanced SQL Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
第 5 章 深入 Response 物件 製作. 網頁的轉向與強制輸出 - 讓網頁轉彎的 Redirect 敘述 運用 Response 物件的 Redirect 方法,將瀏覽器顯 示的網頁,導向至其他網頁,語法如下: Response.Redirect 網頁路徑與名稱 此網頁路徑與名稱  若是導向到同一台.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
最新計算機概論 第 5 章 系統程式. 5-1 系統程式的類型 作業系統 (OS) : 介於電腦硬體與 應用軟體之間的 程式,除了提供 執行應用軟體的 環境,還負責分 配系統資源。
IS 4420 Database Fundamentals Chapter 8: Advanced SQL Leon Chen
資料庫程式設計與系統管理 SQL Server 2005 Express 第六章 進階資料庫設計.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
國立聯合大學 資訊管理學系 陳士杰老師 SQL*Plus 與 iSQL*Plus 簡介. 國立聯合大學 資訊管理學系 資料庫系統課程 ( 陳士杰 ) 2 啟動 SQL*Plus 與 iSQL*Plus 方式 Windows 平台.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
資料結構實習-一 參數傳遞.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
Management Abstracts Retrieval System; MARS 檢索操作.
: A-Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10930: A-Sequence 解題者:陳盈村 解題日期: 2008 年 5 月 30 日 題意: A-Sequence 需符合以下的條件, 1 ≤ a.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
函式 Function Part.2 東海大學物理系‧資訊教育 施奇廷. 遞迴( Recursion ) 函式可以「呼叫自己」,這種動作稱為 「遞迴」 此程式的執行結果相當於陷入無窮迴圈, 無法停止(只能按 Ctrl-C ) 這給我們一個暗示:函式的遞迴呼叫可以 達到部分迴圈的效果.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Chapter 10 m-way 搜尋樹與B-Tree
: Function Overloading ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11032:Function Overloading 解題者:許智祺 解題日期: 2007 年 5 月 8 日 題意:判對輸入之數字是否為.
: Help My Brother ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11033: Help My Brother 解題者: 呂明璁 解題日期: 2007 年 5 月 14 日.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
2005/7 Linear system-1 The Linear Equation System and Eliminations.
ArcINFO &Geodatabase 由 ESRI 產生 1970 ArcINFO 一開始被設計在迷你電 腦上, 後來逐漸發展, 在 UNIX 系統上也能 執行, 直到今天, 已經可以在不同的平台上 運作.
SQL 進階查詢.
Cambridge Scientific Abstracts 系列資料庫 圖 書 館
函式 Function 東海大學物理系‧資訊教育 施奇廷. 函式簡介 當程式越來越大、越複雜時,程式的維護、 除錯會變得更困難,此時必須引入函式來 簡化程式或將程式分段,將程式重複的部 分改寫為函式,將程式「模組化」 這種作法有下列優點:節省程式發展的時 間、邏輯容易瞭解、程式容易除錯、可分 工合作完成程式.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
著作權所有 © 旗標出版股份有限公司 第 14 章 製作信封、標籤. 本章提要 製作單一信封 製作單一郵寄標籤.
幼兒行為觀察與記錄 第八章 事件取樣法.
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
© 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 CHAPTER 7: ADVANCED SQL Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh,
Copyright © 2014 Pearson Education, Inc. 1 CHAPTER 7: ADVANCED SQL Essentials of Database Management Jeffrey A. Hoffer, Heikki Topi, V. Ramesh.
Modern Database Management
1 Chapter 8: Advanced SQL. Chapter 8 2 Processing Multiple Tables – Joins Join – a relational operation that causes two or more tables with a common domain.
Dr. Chen, Data Base Management Chapter 7: Advanced SQL Jason C. H. Chen, Ph.D. Professor of MIS School of Business Administration Gonzaga University Spokane,
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 7: Advanced SQL Modern Database Management 10 th Edition Jeffrey A. Hoffer, V. Ramesh,
Chapter 7: advanced sql Jeffrey A. Hoffer, V. Ramesh, Heikki Topi
1 Chapter 8: Advanced SQL Modern Database Management Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
1 © Prentice Hall, 2002 Chapter 8: Advanced SQL Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
Modern Database Management Chapter 8: Advanced SQL.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 8: Advanced SQL Modern Database Management 9 th Edition Jeffrey A. Hoffer, Mary B.
SQL1-ch5 顯示多個表格的資料. 題號  80 題: 34 、 57 、 71 、 72  140 題: 18 、 25 、 62 、 97 、 115 、 131.
Chapter 7: advanced sql Jeffrey A. Hoffer, V. Ramesh, Heikki Topi
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
ERP Purge Manual 2007/10/2 TinaLee. 2 Purge Job  Interface Purge  Transaction Purge  Other DataPurge (Like Customer 、 Vendor 、 Employee Data)
Copyright © 2016 Pearson Education, Inc. CHAPTER 7: ADVANCED SQL (PART I) Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki.
CSC314 DAY 9 Intermediate SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall USING AND DEFINING VIEWS  Views provide users controlled.
Chapter 8 1 Lecture Advanced SQL. Chapter 8 2 Processing Multiple Tables–Joins Join – a relational operation that causes two or more tables with.
Modern Database Management Jeffrey A. Hoffer, Mary B. Prescott,
CHAPTER 7: ADVANCED SQL.
Modern Database Management Jeff Hoffer, Ramesh Venkataraman,
Presentation transcript:

2013 Fall 1 Chapter 8: Advanced SQL 楊立偉教授 台灣大學工管系 註 : 於 11 版為 Chapter 7

Chapter 8 2 Processing Multiple Tables–Joins Join – a relational operation that causes two or more tables with a common domain to be combined into a single table or view Join – a relational operation that causes two or more tables with a common domain to be combined into a single table or view Equi-join – a join in which the joining condition is based on equality between values in the common columns; common columns appear redundantly in the result table Equi-join – a join in which the joining condition is based on equality between values in the common columns; common columns appear redundantly in the result table Natural join – an equi-join in which one of the duplicate columns is eliminated in the result table Natural join – an equi-join in which one of the duplicate columns is eliminated in the result table Outer join – a join in which rows that do not have matching values in common columns are nonetheless included in the result table (as opposed to inner join, in which rows must have matching values in order to appear in the result table) Outer join – a join in which rows that do not have matching values in common columns are nonetheless included in the result table (as opposed to inner join, in which rows must have matching values in order to appear in the result table) Union join – includes all columns from each table in the join, and an instance for each row of each table Union join – includes all columns from each table in the join, and an instance for each row of each table The common columns in joined tables are usually the primary key of the dominant table and the foreign key of the dependent table in 1:M relationships

Chapter 8 3 Figure 8-2 Visualization of different join types with results returned in shaded area

Chapter 8 4 Equi-join 的結果 最原始, 由等號連結 SELECT Order.*, Customer.*, Product.* FROM Order JOIN Customer ON Order.c_id=Customer.id JOIN Product ON Order.p_id=Product.id Natural join 的結果 其中必有部份欄位之值 完全相同 (Join 條件 ) 將之剔除不顯示

Chapter 8 5 Equi-join 的結果 最原始, 由等號連結 SELECT Emp.*, Dept.* FROM Emp JOIN Dept ON Emp.dep_no=Dept.no Left outer join 的結果 Left : 以左邊為主 Outer : 不管是否有關聯到, 均列出 ← 注意這筆 SELECT Emp.*, Dept.* FROM Emp LEFT OUTER JOIN Dept ON Emp.dep_no=Dept.no

Chapter 8 6 SELECT Emp.*, Dept.* FROM Emp JOIN Dept ON Emp.dep_no=Dept.no Left inner join 的結果 Left : 以左邊為主 Inner : 有關聯到的才列出 → 結果又等同 Equi-join ← 注意這筆 SELECT Emp.*, Dept.* FROM Emp LEFT INNER JOIN Dept ON Emp.dep_no=Dept.no 預設就是 inner 很少特別指定

Chapter 8 7 Union-join 的結果 垂直合併 兩張表格必需聯集相容 Union Compatible → 兩張表格有相同之欄位, 且相對應之欄位有相同值域 合併後的結果必需符合表格特徵 → 任兩筆完全相同紀錄的會被合併 SELECT * FROM Customer_TPE SELECT * FROM Customer_HKG SELECT * FROM Customer_TPE UNION SELECT * FROM Customer_HKG

Chapter 8 8 Figure 8-1 Pine Valley Furniture Company Customer and Order tables with pointers from customers to their orders (how Join works) 有 15 個客戶 有 10 筆訂單

Chapter 8 9 For each customer who placed an order, what is the customer’s name and order number? For each customer who placed an order, what is the customer’s name and order number? SELECT CUSTOMER_T.CUSTOMER_ID, CUSTOMER_NAME, ORDER_ID FROM CUSTOMER_T NATURAL JOIN ORDER_T ON CUSTOMER_T.CUSTOMER_ID = ORDER_T.CUSTOMER_ID; Join involves multiple tables in FROM clause Natural Join Example ON clause performs the equality check for common columns of the two tables Note: from Fig. 1, you see that only 10 Customers have links with orders  Only 10 rows will be returned from this INNER join

Chapter 8 10 List the customer name, ID number, and order number for all customers. Include customer information even for customers that do have an order List the customer name, ID number, and order number for all customers. Include customer information even for customers that do have an order SELECT CUSTOMER_T.CUSTOMER_ID, CUSTOMER_NAME, ORDER_ID FROM CUSTOMER_T LEFT OUTER JOIN ORDER_T ON CUSTOMER_T.CUSTOMER_ID = ORDER_T.CUSTOMER_ID; Outer Join Example LEFT OUTER JOIN syntax with ON causes customer data to appear even if there is no corresponding order data 會回傳 15 筆

Chapter 8 11 Results Unlike INNER join, this will include customer rows with no matching order rows

Chapter 8 12 Assemble all information necessary to create an invoice for order number 1006 Assemble all information necessary to create an invoice for order number 1006 SELECT CUSTOMER_T.CUSTOMER_ID, CUSTOMER_NAME, CUSTOMER_ADDRESS, CITY, SATE, POSTAL_CODE, ORDER_T.ORDER_ID, ORDER_DATE, QUANTITY, PRODUCT_DESCRIPTION, STANDARD_PRICE, (QUANTITY * UNIT_PRICE) FROM CUSTOMER_T, ORDER_T, ORDER_LINE_T, PRODUCT_T WHERE CUSTOMER_T.CUSTOMER_ID = ORDER_LINE.CUSTOMER_ID AND ORDER_T.ORDER_ID = ORDER_LINE_T.ORDER_ID AND ORDER_LINE_T.PRODUCT_ID = PRODUCT.PRODUCT_ID AND ORDER_T.ORDER_ID = 1006; Four tables involved in this join Multiple Table Join Example Each pair of tables requires an equality-check condition in the WHERE clause, matching primary keys against foreign keys

Chapter 8 13 SELECT CUSTOMER_T.CUSTOMER_ID, CUSTOMER_NAME, CUSTOMER_ADDRESS, CITY, SATE, POSTAL_CODE, ORDER_T.ORDER_ID, ORDER_DATE, QUANTITY, PRODUCT_DESCRIPTION, STANDARD_PRICE, (QUANTITY * UNIT_PRICE) FROM CUSTOMER_T, ORDER_T, ORDER_LINE_T, PRODUCT_T WHERE CUSTOMER_T.CUSTOMER_ID = ORDER_LINE.CUSTOMER_ID AND ORDER_T.ORDER_ID = ORDER_LINE_T.ORDER_ID AND ORDER_LINE_T.PRODUCT_ID = PRODUCT.PRODUCT_ID AND ORDER_T.ORDER_ID = 1006; Multiple Table Join Example SELECT … FROM CUSTOMER_T AS C JOIN ORDER_LINE_T AS L ON C.CUSTOMER_ID = L.CUSTOMER_ID JOIN ORDER_T AS O ON O.ORDER_ID = L.ORDER_ID JOIN PRODUCT_T AS P ON L.PRODUCT_ID = P.PRODUCT_ID WHERE ORDER_T.ORDER_ID = 1006; 改用 JOIN 寫有同樣效果

Chapter 8 14 Figure 8-4 Results from a four-table join From CUSTOMER_T table From ORDER_T table From PRODUCT_T table

Chapter 8 Self-Join Example 15 The same table is used on both sides of the join; distinguished using table aliases Self-joins are usually used on tables with unary relationships.

Chapter 8 16 Figure Example of a self-join

Chapter 8 17 Processing Multiple Tables Using Subqueries Subquery 因為查詢的結果還是表格,因此可對結果再查詢 Subquery 因為查詢的結果還是表格,因此可對結果再查詢 placing an inner query (SELECT statement) inside placing an inner query (SELECT statement) inside Options: Options: In a condition of the WHERE clause In a condition of the WHERE clause As a “table” of the FROM clause As a “table” of the FROM clause In the HAVING clause In the HAVING clause Subqueries can be: Subqueries can be: Noncorrelated–executed once for the entire outer query Noncorrelated–executed once for the entire outer query Correlated–executed once for each row returned by the outer query Correlated–executed once for each row returned by the outer query 每行資料都得執行一次子查詢

Chapter 8 18 Show all customers who have placed an order Show all customers who have placed an order SELECT CUSTOMER_NAME FROM CUSTOMER_T WHERE CUSTOMER_ID IN (SELECT DISTINCT CUSTOMER_ID FROM ORDER_T); Subquery Example Subquery is embedded in parentheses. In this case it returns a list that will be used in the WHERE clause of the outer query The IN operator will test to see if the CUSTOMER_ID value of a row is included in the list returned from the subquery

Chapter 8 Join vs. Subquery Some queries could be accomplished by either a join or a subquery Some queries could be accomplished by either a join or a subquery 19 Join version Subquery version

Chapter 8 20 Figure Graphical depiction of two ways to answer a query with different types of joins

Chapter 8 21 Figure Graphical depiction of two ways to answer a query with different types of joins

Chapter 8 22 Correlated vs. Noncorrelated Subqueries Noncorrelated subqueries: Noncorrelated subqueries: Do not depend on data from the outer query Do not depend on data from the outer query Execute once for the entire outer query Execute once for the entire outer query Correlated subqueries: Correlated subqueries: Make use of data from the outer query Make use of data from the outer query Execute once for each row of the outer query Execute once for each row of the outer query Can use with EXISTS operator 可搭配使用 Can use with EXISTS operator 可搭配使用

Chapter 8 23 Figure 8-6a Processing a noncorrelated subquery No reference to data in outer query, so subquery executes once only These are the only customers that have IDs in the ORDER_T table

Chapter 8 24 Show all orders that include furniture finished in natural ash Show all orders that include furniture finished in natural ash Correlated Subquery Example The subquery is testing for a value that comes from the outer query The EXISTS operator will return a TRUE value if the subquery resulted in a non-empty set, otherwise it returns a FALSE  A correlated subquery always refers to an attribute from a table referenced in the outer query

Chapter 8 25 Figure 8-6b Processing a correlated subquery Subquery refers to outer-query data, so executes once for each row of outer query ( 需花 較多執行時間 )

Chapter 8 26 Show all products whose standard price is higher than the average price Show all products whose standard price is higher than the average price SELECT PRODUCT_DESCRIPTION, STANDARD_PRICE FROM PRODUCT_T WHERE STANDARD_PRICE > (SELECT AVG(STANDARD_PRICE) AVGPRICE FROM PRODUCT_T) Another Subquery Example

Chapter 8 27 Union Queries Combine the output (union of multiple queries) together into a single result table Combine the output (union of multiple queries) together into a single result table First query Second query Combine

Chapter 8 28 Tips for Developing Queries Be familiar with the data model (entities and relationships) Be familiar with the data model (entities and relationships) Understand the desired results Understand the desired results Know the attributes desired in result Know the attributes desired in result Identify the entities that contain desired attributes Identify the entities that contain desired attributes Review ERD Review ERD Construct a WHERE for each link 知道去哪查表 Construct a WHERE for each link 知道去哪查表 Fine tune with GROUP BY and HAING clauses if needed Fine tune with GROUP BY and HAING clauses if needed

Chapter 8 Guidelines for Better Query Design Write simple queries 越簡單越好 Write simple queries 越簡單越好 Break complex queries into multiple simple parts 把複雜查詢做拆解 Break complex queries into multiple simple parts 把複雜查詢做拆解 If possible, avoid subquery and self-joins If possible, avoid subquery and self-joins Create temporary tables for groups of queries Create temporary tables for groups of queries Retrieve only the data you need i.e. 不取多餘的 欄位或資料 Retrieve only the data you need i.e. 不取多餘的 欄位或資料 Consider the total query processing time Consider the total query processing time Don’t have the DBMS sort without an index Don’t have the DBMS sort without an index Learn and practice 對複雜查詢多試不同的寫法 Learn and practice 對複雜查詢多試不同的寫法 29

Chapter 8 30 Ensuring Transaction Integrity Transaction = A discrete unit of work that must be completely processed or not processed at all 確保動作完成不被中斷分割 Transaction = A discrete unit of work that must be completely processed or not processed at all 確保動作完成不被中斷分割 May involve multiple updates May involve multiple updates If any update fails, then all other updates must be cancelled If any update fails, then all other updates must be cancelled SQL commands for transactions SQL commands for transactions BEGIN TRANSACTION/END TRANSACTION BEGIN TRANSACTION/END TRANSACTION Marks boundaries of a transaction Marks boundaries of a transaction COMMIT COMMIT Makes all updates permanent Makes all updates permanent ROLLBACK ROLLBACK Cancels updates since the last COMMIT Cancels updates since the last COMMIT

Chapter 8 31 Figure 8-9 An SQL Transaction sequence (in pseudocode)

Chapter 8 32 Routines and Triggers Routines Routines Program modules that execute on demand Program modules that execute on demand Include Functions and Procedures Include Functions and Procedures Ex. 預先寫好的常用 SQL 指令 Triggers Triggers Routines that execute in response to a database event (INSERT, UPDATE, or DELETE) Routines that execute in response to a database event (INSERT, UPDATE, or DELETE) Ex. 當 INSERT 至 ORDER 表格時,自動也 INSERT 至 ORDER_LOG 表格

Chapter 8 33 Figure 8-10 Triggers contrasted with stored procedures Procedures are called explicitly Triggers are event-driven Source: adapted from Mullins, 1995.

Chapter 8 34 Figure 8-11 Simplified trigger syntax, SQL:2008 Figure 8-12 Create routine syntax, SQL:2008

Chapter 8 Conditional Expressions Using Case Syntax This is available with newer versions of SQL, previously not part of the standard 35

Chapter 8 36 Embedded and Dynamic SQL Embedded SQL Embedded SQL Including SQL statements in a program Including SQL statements in a program 將 SQL 指令放在 C 或 Java 程式內一起使用 Dynamic SQL Dynamic SQL use program to generate SQL code on the fly use program to generate SQL code on the fly 於程式內即時產生所需的 SQL 指令 Ex. 輸入客戶名稱檢查是否存在 Ex. 輸入客戶名稱檢查是否存在 SELECT count(*) FROM CUSTOMER WHERE NAME=$var_customer_name