



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















Spring 2009
4/1/^
Luke Huan Univ. of Kansas
statements
4/1/^
Luke Huan Univ. of Kansas Quantified subqueries
z^ A quantified subquery can be used as a value in a
WHERE
condition z Universal quantification (for all):…^ WHERE
x op^ ALL
( subquery
) …
z^ True iff for all
t^ in the result of
subquery
,^ x op t
z^ Existential quantification (exists):…^
WHERE
x op^ ANY
( subquery
) …
z^ True iff there exists some
t^ in the result of
subquery
such that
x op t
)^ Beware^ z^ In common parlance, “any” and “all” seem to be synonyms^ z^ In SQL,
ANY^ really means “some” z^ Also may use
EXISTS (NOT EXISTS), IN (NOT IN)
4/1/^
Luke Huan Univ. of Kansas
Examples of quantified subqueries
Employee WHERE
Salary
Salary
Employee);
Employee WHERE
Salary
salary
Employee);
4/1/^
Luke Huan Univ. of Kansas
Nested Queries: Scoping
Start with the immediately surrounding query z If not found, look in the one surrounding that; repeat ifnecessary
4/1/^
Luke Huan Univ. of Kansas An Example
Students who are taking at least two courses
4/1/^
Luke Huan Univ. of Kansas Database Design
z^ Active database z^ View z^ Indexing z^ Thinking about the following “real-world” situationYou need to design a database for students to record studentname, gpa (>0), id, email address, home department, and images.Constraints: student id is the primary key, student gpa can not benegative, a student may take up to 10 courses in a semester(unless they are senior), and whenever a new honor student isentered in the table, this student is automatically enrolled a honorcourse “Bio101, How Jayhawk fly”
4/1/^
Luke Huan Univ. of Kansas Active Database
Check z Assertion z Trigger
4/1/^
Luke Huan Univ. of Kansas Assertion
4/1/^
Luke Huan Univ. of Kansas Trigger example
Event
Condition
Action
4/1/^
Luke Huan Univ. of Kansas Why use views?
If applications deal with views, we can change theunderlying schema without affecting applications z Recall physical data independence: change the physicalorganization of data without affecting applications
4/1/^
Luke Huan Univ. of Kansas
Creating and dropping views
EECS647Roster
name,
age,
Student WHERE
Enroll
view_name
Called “base tables”
4/1/^
Luke Huan Univ. of Kansas Modifying views
4/1/^
Luke Huan Univ. of Kansas A simple case