Computing & Information Sciences Kansas State University Tuesday, 06 Feb 2007 CIS 560: Database System Concepts Lecture 10 of 42 Tuesday, 06 February 2007 William H. Hsu Department of Computing and Information Sciences, KSU KSOL course page: http://snipurl.com/va60 Course web site: http://www.kddresearch.org/Courses/Fall-2006/CIS560 Instructor home page: http:// www.cis.ksu.edu/~bhsu Reading for Next Class: Rest of Chapter 5, Silberschatz et al., 5 th edition JDBC Primer (to be posted on Handouts page) Notes: MP2 Questions, Advanced SQL and Relational Calculus Preliminaries
Lecture 10 of 42. Notes: MP2 Questions, Advanced SQL and Relational Calculus Preliminaries. Tuesday, 06 February 2007 William H. Hsu Department of Computing and Information Sciences, KSU KSOL course page: http://snipurl.com/va60 - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
Lecture 10 of 42
Tuesday, 06 February 2007
William H. Hsu
Department of Computing and Information Sciences, KSU
KSOL course page: http://snipurl.com/va60
Course web site: http://www.kddresearch.org/Courses/Fall-2006/CIS560
Instructor home page: http://www.cis.ksu.edu/~bhsu
Reading for Next Class:
Rest of Chapter 5, Silberschatz et al., 5th edition
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
ViewsViews
In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.)
Consider a person who needs to know a customer’s loan number but has no need to see the loan amount. This person should see a relation described, in SQL, by
(select customer_name, loan_number from borrower, loan where borrower.loan_number = loan.loan_number )
A view provides a mechanism to hide certain data from the view of certain users.
Any relation that is not of the conceptual model but is made visible to a user as a “virtual relation” is called a view.
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
ViewsViews
In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.)
Consider a person who needs to know a customer’s loan number but has no need to see the loan amount. This person should see a relation described, in SQL, by
(select customer_name, loan_number from borrower, loan where borrower.loan_number = loan.loan_number )
A view provides a mechanism to hide certain data from the view of certain users.
Any relation that is not of the conceptual model but is made visible to a user as a “virtual relation” is called a view.
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
View DefinitionView Definition
A view is defined using the create view statement which has the form
create view v as < query expression >
where <query expression> is any legal SQL expression. The view name is represented by v.
Once a view is defined, the view name can be used to refer to the virtual relation that the view generates.
View definition is not the same as creating a new relation by evaluating the query expression Rather, a view definition causes the saving of an expression; the
expression is substituted into queries using the view.
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
Example QueriesExample Queries
A view consisting of branches and their customers
Find all customers of the Perryridge branch
create view all_customer as (select branch_name, customer_name from depositor, account where depositor.account_number =
account.account_number ) union (select branch_name, customer_name from borrower, loan where borrower.loan_number = loan.loan_number )
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
Procedural Extensions and Stored Procedures
Procedural Extensions and Stored Procedures
SQL provides a module language Permits definition of procedures in SQL, with if-then-else statements,
for and while loops, etc. more in Chapter 9
Stored Procedures Can store procedures in the database then execute them using the call statement permit external applications to operate on the database without
knowing about internal details
These features are covered in Chapter 9 (Object Relational Databases)
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
The Power of RecursionThe Power of Recursion
Recursive views make it possible to write queries, such as transitive closure queries, that cannot be written without recursion or iteration. Intuition: Without recursion, a non-recursive non-iterative program
can perform only a fixed number of joins of manager with itselfThis can give only a fixed number of levels of managersGiven a program we can construct a database with a greater number of
levels of managers on which the program will not work
The next slide shows a manager relation and each step of the iterative process that constructs empl from its recursive definition. The final result is called the fixed point of the recursive view definition.
Recursive views are required to be monotonic. That is, if we add tuples to manger the view contains all of the tuples it contained before, plus possibly more
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
Example of Fixed-Point ComputationExample of Fixed-Point Computation
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
Chapter 5: Other Relational LanguagesChapter 5: Other Relational Languages
A nonprocedural query language, where each query is of the form
{t | P (t ) } It is the set of all tuples t such that predicate P is true for t t is a tuple variable, t [A ] denotes the value of tuple t on attribute A t r denotes that tuple t is in relation r P is a formula similar to that of the predicate calculus
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts
Predicate Calculus FormulaPredicate Calculus Formula
1. Set of attributes and constants
2. Set of comparison operators: (e.g., , , , , , )
3. Set of connectives: and (), or (v)‚ not ()
4. Implication (): x y, if x if true, then y is true
x y x v y
5. Set of quantifiers: t r (Q (t )) ”there exists” a tuple in t in relation r
such that predicate Q (t ) is true t r (Q (t )) Q is true “for all” tuples t in relation r
Computing & Information SciencesKansas State University
Tuesday, 06 Feb 2007CIS 560: Database System Concepts