Академический Документы
Профессиональный Документы
Культура Документы
Advanced SQL
Modern Database
Management
8th Edition
Jeffrey A. Hoffer, Mary B. Prescott,
Fred R. McFadden
2007 by Prentice Hall
Objectives
Definition of terms
Write multiple table SQL queries
Define and use three types of joins
Write correlated and noncorrelated
subqueries
Establish referential integrity in SQL
Understand triggers and stored procedures
Discuss SQL:1999 standard and its
extension of SQL-92
Chapter 8
Chapter 8
Results
Unlike
INNER
join, this
will
include
customer
rows with
no
matching
order
rows
Chapter 8
Chapter 8
AND
10
Chapter 8
11
Subquery Example
SELECT CUSTOMER_NAME
WHERE CUSTOMER_ID IN
(SELECT DISTINCT CUSTOMER_ID FROM ORDER_T);
Subquery is embedded in
parentheses. In this case it
returns a list that will be used
in the WHERE clause of the
outer query
Chapter 8
12
Correlated vs.
Noncorrelated Subqueries
Noncorrelated subqueries:
Correlated subqueries:
Chapter 8
13
Figure 8-3a
Processing a
noncorrelated
subquery
1.
The subquery
executes and
returns the
customer IDs
from the
ORDER_T table
2.
Chapter 8
No reference to data
in outer query, so
subquery executes
once only
14
Correlated Subquery
Example
15
Figure 8-3b
Processing a
correlated
subquery
Chapter 8
16
Show all products whose standard price is higher than the average price
The WHERE clause normally cannot include aggregate functions, but because the
aggregate is performed in the subquery its result can be used in the outer querys
WHERE clause
Chapter 8
17
Union Queries
First query
Combine
Second query
Chapter 8
18
Chapter 8
19
Ensuring Transaction
Integrity
COMMIT
ROLLBACK
Chapter 8
20
Chapter 8
21
DBA_TABLESdescriptions of tables
DBA_CONSTRAINTSdescription of constraints
DBA_USERSinformation about the users of the system
Chapter 8
22
Chapter 8
23
Chapter 8
24
Routines
Triggers
Chapter 8
25
Chapter 8
26
Chapter 8
27
Embedded SQL
Dynamic SQL
Chapter 8
28