Database Design-Database System Concepts-Lecture 12 Slides-Computer Science, Slides of Database Management Systems (DBMS)

Database Design, Relational Calculi, Domain Relational Calculus, Nonprocedural, Safety, Recursion in SQL, Query-by-example, QBE, Structure, Graphical, Two dimensional Syntax, Skeleton, Modification, Deletion, Insertion, Updates, Microsoft Access QBE, Aggregation, Entity-Relationship Model, Modeling, Entities, Relationship, Attributes, Properties, Relationship Sets, Relational Database Design, Schemas, Smaller Schemas, Decompose, Functional Dependency, Candidate Key, Lossy Decomposition, First No

Typology: Slides

2011/2012

Uploaded on 01/31/2012

beatryx
beatryx 🇺🇸

4.6

(16)

289 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Computing & Information Sciences
Kansas State University
Wednesday, 20 Sep 2006CIS 560: Database System Concepts
Lecture 12 of 42
Wednesday, 20 September 2006
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:
Section 6.1 – 6.2, Silberschatz et al., 5th edition
Database Design Overview
Notes: Relational Calculi, PS3
Computing & Information Sciences
Kansas State University
Wednesday, 20 Sep 2006CIS 560: Database System Concepts
Domain Relational Calculus
Domain Relational Calculus
zA nonprocedural query language equivalent in power to the tuple
relational calculus
zEach query is an expression of the form:
{ <x1, x2, …, xn>| P (x1, x2, …, xn)}
x1, x2, …, xnrepresent domain variables
Prepresents a formula similar to that of the predicate calculus
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Database Design-Database System Concepts-Lecture 12 Slides-Computer Science and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Lecture 12 of 42

Wednesday, 20 September 2006

William H. Hsu

Department of Computing and Information Sciences, KSU

KSOL course page: http://snipurl.com/va Course web site: http://www.kddresearch.org/Courses/Fall-2006/CIS Instructor home page: http://www.cis.ksu.edu/~bhsu

Reading for Next Class: Section 6.1 – 6.2, Silberschatz et al. , 5th^ edition

Database Design Overview

Notes: Relational Calculi, PS

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Domain Relational CalculusDomain Relational Calculus

z A nonprocedural query language equivalent in power to the tuple

relational calculus

z Each query is an expression of the form:

{ < x 1 , x 2 , …, x n > | P ( x 1 , x 2 , …, x n )}

’ x 1 , x 2 , …, xn represent domain variables ’ P represents a formula similar to that of the predicate calculus

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Example Queries Example Queries

z Find the loan_number, branch_name, and amount for loans of

over $

„ Find the names of all customers who have a loan from the Perryridge branch and the loan amount: f {< c, a > | ∃ l (< c, l > ∈ borrower ∧ ∃ b (< l, b, a > ∈ loanb = “Perryridge”))} f {< c, a > | ∃ l (< c, l > ∈ borrower ∧ < l, “ Perryridge ”, a > ∈ loan )}

{< c > | ∃ l, b, a (< c, l > ∈ borrower ∧ < l, b, a > ∈ loana > 1200)}

„ Find the names of all customers who have a loan of over $

{< l , b, a > | < l , b, a > ∈ loana > 1200}

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Example Queries Example Queries

z Find the names of all customers having a loan, an account, or

both at the Perryridge branch:

{< c > | ∃ s, n (< c, s, n > ∈ customer) ∧ ∀ x,y,z (< x, y, z > ∈ branchy = “Brooklyn”) ⇒ ∃ a,b (< x, y, z > ∈ account ∧ < c,a > ∈ depositor )}

„ Find the names of all customers who have an account at all branches located in Brooklyn:

{< c > | ∃ l ( < c, l > ∈ borrower ∧ ∃ b,a (< l, b, a > ∈ loanb = “Perryridge”)) ∨ ∃ a (< c, a > ∈ depositor ∧ ∃ b,n (< a, b, n > ∈ accountb = “Perryridge”))}

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Query-by-Example (QBE) Query-by-Example (QBE)

z Basic Structure

z Queries on One Relation

z Queries on Several Relations

z The Condition Box

z The Result Relation

z Ordering the Display of Tuples

z Aggregate Operations

z Modification of the Database

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

QBE — Basic Structure QBE — Basic Structure

z A graphical query language which is based (roughly) on the

domain relational calculus

z Two dimensional syntax – system creates templates of

relations that are requested by users

z Queries are expressed “by example”

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

QBE Skeleton Tables for the Bank ExampleQBE Skeleton Tables for the Bank Example

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Query Example Query Example

z Find all customers who have an account at all branches located

in Brooklyn.

’ Approach: for each customer, find the number of branches in Brooklyn at which they have accounts, and compare with total number of branches in Brooklyn ’ QBE does not provide subquery functionality, so both above tasks have to be combined in a single query. Ö Can be done for this query, but there are queries that require subqueries and cannot always be expressed in QBE.

„ In the query on the next page f CNT.UNQ.ALL._ w specifies the number of distinct branches in Brooklyn. Note: The variable _ w is not connected to other variables in the query f CNT.UNQ.ALL._ z specifies the number of distinct branches in Brooklyn at which customer x has an account.

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Deletion Query ExamplesDeletion Query Examples

z Delete all loans with a loan amount greater than $1300 and less

than $1500.

’ For consistency, we have to delete information from loan and borrower tables

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Deletion Query Examples (Cont.) Deletion Query Examples (Cont.)

z Delete all accounts at branches located in Brooklyn.

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Modification of the Database – InsertionModification of the Database – Insertion

z Insertion is done by placing the I. operator in the query

expression.

z Insert the fact that account A-9732 at the Perryridge branch

has a balance of $700.

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Modification of the Database – Insertion (Cont.) Modification of the Database – Insertion (Cont.)

„ Provide as a gift for all loan customers of the Perryridge branch, a new $200 savings account for every loan account they have, with the loan number serving as the account number for the new savings account.

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

An Example Query in Microsoft Access QBE An Example Query in Microsoft Access QBE

„ Example query: Find the customer_name , account_number and balance for all accounts at the Perryridge branch

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

An Aggregation Query in Access QBE An Aggregation Query in Access QBE

„ Find the name, street and city of all customers who have more than one account at the bank

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Aggregation in Access QBE Aggregation in Access QBE

z The row labeled Total specifies

’ which attributes are group by attributes ’ which attributes are to be aggregated upon (and the aggregate function). ’ For attributes that are neither group by nor aggregated, we can still specify conditions by selecting where in the Total row and listing the conditions below

z As in SQL, if group by is used, only group by attributes and

aggregate results can be output

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Banking ExampleBanking Example

z branch ( branch_name, branch_city, assets )

z customer ( customer_name, customer_street, customer_city )

z account ( account_number, branch_name, balance )

z loan ( loan_number, branch_name, amount )

z depositor ( customer_name, account_number )

z borrower ( customer_name, loan_number )

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Entity SetsEntity Sets^ customercustomer^ andand loanloan customer_id customer_ customer_ customer_ loan_ amount name street city number

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Relationship Sets Relationship Sets

z A relationship is an association among several entities

Example:

Hayes depositor A-

customer entity relationship set account entity

z A relationship set is a mathematical relation among n ≥ 2

entities, each taken from entity sets

{( e 1 , e 2 , … e n ) | e 1 ∈ E 1 , e 2 ∈ E 2 , …, e n ∈ En }

where ( e 1 , e 2 , …, e n ) is a relationship

’ Example: (Hayes, A-102) ∈ depositor

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Relationship SetRelationship Set borrowerborrower

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

Relational Database DesignRelational Database Design

z Features of Good Relational Design

z Atomic Domains and First Normal Form

z Decomposition Using Functional Dependencies

z Functional Dependency Theory

z Algorithms for Functional Dependencies

z Decomposition Using Multivalued Dependencies

z More Normal Form

z Database-Design Process

z Modeling Temporal Data

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

A Combined Schema Without RepetitionA Combined Schema Without Repetition

z Consider combining loan_branch and loan

loan_amt_br = ( loan_number , amount , branch_name )

z No repetition (as suggested by example below)

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

What About Smaller Schemas?What About Smaller Schemas?

z Suppose we had started with bor_loan. How would we know to split up ( decompose ) it into borrower and loan? z Write a rule “if there were a schema ( loan_number, amount ), then loan_number would be a candidate key” z Denote as a functional dependency : loan_numberamount z In bor_loan , because loan_number is not a candidate key, the amount of a loan may have to be repeated. This indicates the need to decompose bor_loan. z Not all decompositions are good. Suppose we decompose employee into employee1 = ( employee_id , employee_name ) employee2 = ( employee_name , telephone_number , start_date ) z The next slide shows how we lose information -- we cannot reconstruct the original employee relation -- and so, this is a lossy decomposition.

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

A Lossy Decomposition A Lossy Decomposition

Computing & Information Sciences CIS 560: Database System Concepts Wednesday, 20 Sep 2006 Kansas State University

First Normal Form First Normal Form

z Domain is atomic if its elements are considered to be indivisible

units

’ Examples of non-atomic domains: Ö Set of names, composite attributes Ö Identification numbers like CS101 that can be broken up into parts

z A relational schema R is in first normal form if the domains of all

attributes of R are atomic

z Non-atomic values complicate storage and encourage redundant

(repeated) storage of data

’ Example: Set of accounts stored with each customer, and set of owners stored with each account ’ We assume all relations are in first normal form (and revisit this in Chapter 9)