RELATIONAL MODEL.

Similar documents
BİL 354 Veritabanı Sistemleri. Relational Algebra (İlişkisel Cebir)

DATABASE DESIGN I - 1DL300

DATABASTEKNIK - 1DL116

INF1383 -Bancos de Dados

Learning Goals. Relational Query Languages. Formal Relational Query Languages. Formal Query Languages: Relational Algebra and Relational Calculus

Before we can begin Ch. 3 on Radicals, we need to be familiar with perfect squares, cubes, etc. Try and do as many as you can without a calculator!!!

Nondeterminism and Nodeterministic Automata

Riemann Sums and Riemann Integrals

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Riemann Sums and Riemann Integrals

7.2 The Definite Integral

The Regulated and Riemann Integrals

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

CS5371 Theory of Computation. Lecture 20: Complexity V (Polynomial-Time Reducibility)

Properties of Integrals, Indefinite Integrals. Goals: Definition of the Definite Integral Integral Calculations using Antiderivatives

CS 275 Automata and Formal Language Theory

Goals: Determine how to calculate the area described by a function. Define the definite integral. Explore the relationship between the definite

State space systems analysis (continued) Stability. A. Definitions A system is said to be Asymptotically Stable (AS) when it satisfies

Duality # Second iteration for HW problem. Recall our LP example problem we have been working on, in equality form, is given below.

ARITHMETIC OPERATIONS. The real numbers have the following properties: a b c ab ac

UNIT 1 FUNCTIONS AND THEIR INVERSES Lesson 1.4: Logarithmic Functions as Inverses Instruction

Bernoulli Numbers Jeff Morton

Chapter 3 Relational Model

Handout: Natural deduction for first order logic

Boolean Algebra. Boolean Algebras

Unit #9 : Definite Integral Properties; Fundamental Theorem of Calculus

20 MATHEMATICS POLYNOMIALS

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Chapter 5 : Continuous Random Variables

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Boolean algebra.

Recitation 3: More Applications of the Derivative

Chapter 3 MATRIX. In this chapter: 3.1 MATRIX NOTATION AND TERMINOLOGY

New data structures to reduce data size and search time

Continuous Random Variables

Lecture 1. Functional series. Pointwise and uniform convergence.

Improper Integrals, and Differential Equations

Chapter 4 Contravariance, Covariance, and Spacetime Diagrams

W. We shall do so one by one, starting with I 1, and we shall do it greedily, trying

Symbolic enumeration methods for unlabelled structures

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

A REVIEW OF CALCULUS CONCEPTS FOR JDEP 384H. Thomas Shores Department of Mathematics University of Nebraska Spring 2007

Riemann Integrals and the Fundamental Theorem of Calculus

Lecture 3: Equivalence Relations

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

Geometric Sequences. Geometric Sequence a sequence whose consecutive terms have a common ratio.

Quantum Physics II (8.05) Fall 2013 Assignment 2

1.9 C 2 inner variations

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER /2019

Advanced Calculus: MATH 410 Notes on Integrals and Integrability Professor David Levermore 17 October 2004

Lecture Note 9: Orthogonal Reduction

CMDA 4604: Intermediate Topics in Mathematical Modeling Lecture 19: Interpolation and Quadrature

Elementary Linear Algebra

Lesson 1: Quadratic Equations

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

13.3 CLASSICAL STRAIGHTEDGE AND COMPASS CONSTRUCTIONS

Reasoning and programming. Lecture 5: Invariants and Logic. Boolean expressions. Reasoning. Examples

Chapter 2 Finite Automata

Jack Simons, Henry Eyring Scientist and Professor Chemistry Department University of Utah

Each term is formed by adding a constant to the previous term. Geometric progression

Conservation Law. Chapter Goal. 5.2 Theory

Chapter 6 Notes, Larson/Hostetler 3e

Arithmetic & Algebra. NCTM National Conference, 2017

Math Calculus with Analytic Geometry II

Section 14.3 Arc Length and Curvature

Review on Integration (Secs ) Review: Sec Origins of Calculus. Riemann Sums. New functions from old ones.

Homework 3 Solutions

Physics 116C Solution of inhomogeneous ordinary differential equations using Green s functions

Equations and Inequalities

1 Online Learning and Regret Minimization

NUMERICAL INTEGRATION. The inverse process to differentiation in calculus is integration. Mathematically, integration is represented by.

Section 6.1 INTRO to LAPLACE TRANSFORMS

Precalculus Spring 2017

Numerical Linear Algebra Assignment 008

Chapter 1. Basic Concepts

Indefinite Integral. Chapter Integration - reverse of differentiation

Mathematics notation and review

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Review of basic calculus

Lecture 9: LTL and Büchi Automata

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

Strong Bisimulation. Overview. References. Actions Labeled transition system Transition semantics Simulation Bisimulation

Matrix Eigenvalues and Eigenvectors September 13, 2017

KNOWLEDGE-BASED AGENTS INFERENCE

1 The Lagrange interpolation formula

Closure Properties of Regular Languages

Introduction to Group Theory

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

INTRODUCTION TO LINEAR ALGEBRA

ECO 317 Economics of Uncertainty Fall Term 2007 Notes for lectures 4. Stochastic Dominance

Ehrenfeucht-Fraïssé Games: Applications and Complexity. Department of Mathematics and Computer Science University of Udine, Italy ESSLLI 2010 CPH

Matrix Solution to Linear Equations and Markov Chains

Integrals - Motivation

63. Representation of functions as power series Consider a power series. ( 1) n x 2n for all 1 < x < 1

INDIAN INSTITUTE OF TECHNOLOGY BOMBAY MA205 Complex Analysis Autumn 2012

A Matrix Algebra Primer

MATH34032: Green s Functions, Integral Equations and the Calculus of Variations 1

The First Fundamental Theorem of Calculus. If f(x) is continuous on [a, b] and F (x) is any antiderivative. f(x) dx = F (b) F (a).

Transcription:

RELATIONAL MODEL Structure of Reltionl Dtbses Reltionl Algebr Tuple Reltionl Clculus Domin Reltionl Clculus Extended Reltionl-Algebr- Opertions Modifiction of the Dtbse Views

EXAMPLE OF A RELATION

BASIC STRUCTURE Formlly, given sets D, D,. D n reltion r is subset of D x D x x D n Thus reltion is set of n-tuples (,,, n ) where ech i D i Exmple: if customer-nme = {Jones, Smith, Curry, Lindsy} customer-street = {Min, North, Prk} customer-city = {Hrrison, Rye, Pittsfield} Then r = { (Jones, Min, Hrrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsy, Prk, Pittsfield)} is reltion over customer-nme x customer-street x customer-city

ATTRIBUTE TYPES Ech ttribute of reltion hs nme The set of llowed vlues for ech ttribute is clled the domin of the ttribute Attribute vlues re (normlly) required to be tomic, tht is, indivisible E.g. multivlued ttribute vlues re not tomic E.g. composite ttribute vlues re not tomic The specil vlue null is member of every domin The null vlue cuses complictions in the definition of mny opertions we shll ignore the effect of null vlues in our min presenttion nd consider their effect lter

RELATION SCHEMA A, A,, A n re ttributes R = (A, A,, A n ) is reltion schem E.g. Customer-schem = (customer-nme, customer-street, customer-city) r(r) is reltion on the reltion schem R E.g. customer (Customer-schem)

RELATION INSTANCE The current vlues (reltion instnce) of reltion re specified by tble An element t of r is tuple, represented by row in tble ttributes (or columns) customer-nme customer-street customer-city Jones Smith Curry Lindsy Min North North Prk Hrrison Rye Rye Pittsfield tuples (or rows) customer

RELATIONS ARE UNORDERED Order of tuples is irrelevnt (tuples my be stored in n rbitrry order) E.g. ccount reltion with unordered tuples

DATABASE A dtbse consists of multiple reltions Informtion bout n enterprise is broken up into prts, with ech reltion storing one prt of the informtion E.g.: ccount : stores informtion bout ccounts depositor : stores informtion bout which customer owns which ccount customer : stores informtion bout customers Storing ll informtion s single reltion such s bnk(ccount-number, blnce, customer-nme,..) results in repetition of informtion (e.g. two customers own n ccount) the need for null vlues (e.g. represent customer without n ccount) Normliztion theory dels with how to design reltionl schems

THE CUSTOMER RELATION

THE DEPOSITOR RELATION

E-R DIAGRAM FOR THE BANKING ENTERPRISE

SCHEMA DIAGRAM FOR THE BANKING ENTERPRISE

QUERY LANGUAGES Lnguge in which user requests informtion from the dtbse. Ctegories of lnguges procedurl non-procedurl Pure lnguges: Reltionl Algebr Tuple Reltionl Clculus Domin Reltionl Clculus Pure lnguges form underlying bsis of query lnguges tht people use.

RELATIONAL ALGEBRA Procedurl lnguge Six bsic opertors select project union set difference Crtesin product renme The opertors tke one or more reltions s inputs nd give new reltion s result.

SELECT OPERATION EXAMPLE Reltion r A B C D 7 5 7 3 3 0 A=B ^ D > 5 (r) A B C D 7 3 0

SELECT OPERATION Nottion: p (r) p is clled the selection predicte Defined s: p (r) = {t t r nd p(t)} Where p is formul in propositionl clculus consisting of terms connected by : (nd), (or), (not) Ech term is one of: <ttribute> op <ttribute> or <constnt> where op is one of: =,, >,. <. Exmple of selection: brnch-nme= Perryridge (ccount)

PROJECT OPERATION EXAMPLE Reltion r: A B C 0 0 30 40 A,C (r) A C A C =

PROJECT OPERATION Nottion: A, A,, Ak (r) where A, A re ttribute nmes nd r is reltion nme. The result is defined s the reltion of k columns obtined by ersing the columns tht re not listed Duplicte rows removed from result, since reltions re sets E.g. To eliminte the brnch-nme ttribute of ccount ccount-number, blnce (ccount)

UNION OPERATION EXAMPLE Reltions r, s: A B A B 3 r s r s: A B 3

UNION OPERATION Nottion: r s Defined s: r s = {t t r or t s} For r s to be vlid.. r, s must hve the sme rity (sme number of ttributes). The ttribute domins must be comptible (e.g., nd column of r dels with the sme type of vlues s does the nd column of s)

SET DIFFERENCE OPERATION EXAMPLE Reltions r, s: A B A B 3 r s r s: A B

SET DIFFERENCE OPERATION Nottion r s Defined s: r s = {t t r nd t s} Set differences must be tken between comptible reltions. r nd s must hve the sme rity ttribute domins of r nd s must be comptible

CARTESIAN-PRODUCT OPERATION-EXAMPLE Reltions r, s: r x s: A B A B C D 0 0 0 0 0 0 0 0 E b b b b C D 0 0 0 0 E b b r s

CARTESIAN-PRODUCT OPERATION Nottion r x s Defined s: r x s = {t q t r nd q s} Assume tht ttributes of r(r) nd s(s) re disjoint. (Tht is, R S = ). If ttributes of r(r) nd s(s) re not disjoint, then renming must be used.

COMPOSITION OF OPERATIONS Cn build expressions using multiple opertions Exmple: A=C (r x s) r x s A B C D 0 0 0 0 0 0 0 0 E b b b b A B C D E A=C (r x s) 0 0 0 b

RENAME OPERATION Allows us to nme, nd therefore to refer to, the results of reltionl-lgebr expressions. Allows us to refer to reltion by more thn one nme. Exmple: x (E) returns the expression E under the nme X If reltionl-lgebr expression E hs rity n, then x (A, A,, An) (E) returns the result of expression E under the nme X, nd with the ttributes renmed to A, A,., An.

BANKING EXAMPLE brnch (brnch-nme, brnch-city, ssets) customer (customer-nme, customer-street, customer-only) ccount (ccount-number, brnch-nme, blnce) lon (lon-number, brnch-nme, mount) depositor (customer-nme, ccountnumber) borrower (customer-nme, lon-number)

EXAMPLE QUERIES Find ll lons of over $00 mount > 00 (lon) Find the lon number for ech lon of n mount greter thn $00 lon-number ( mount > 00 (lon))

EXAMPLE QUERIES Find the nmes of ll customers who hve lon, n ccount, or both, from the bnk customer-nme (borrower) customer-nme (depositor) Find the nmes of ll customers who hve lon nd n ccount t bnk. customer-nme (borrower) customer-nme (depositor)

EXAMPLE QUERIES Find the nmes of ll customers who hve lon t the Perryridge brnch. customer-nme ( brnch-nme= Perryridge ( borrower.lon-number = lon.lon-number (borrower x lon))) Find the nmes of ll customers who hve lon t the Perryridge brnch but do not hve n ccount t ny brnch of the bnk. customer-nme ( brnch-nme = Perryridge ( borrower.lon-number = lon.lon-number (borrower x lon))) customer-nme (depositor)

EXAMPLE QUERIES Find the nmes of ll customers who hve lon t the Perryridge brnch. Query customer-nme ( brnch-nme = Perryridge ( borrower.lon-number = lon.lon-number (borrower x lon))) Query customer-nme ( lon.lon-number = borrower.lon-number ( ( brnch-nme = Perryridge (lon)) x borrower))

EXAMPLE QUERIES Find the lrgest ccount blnce Renme ccount reltion s d The query is: blnce (ccount) - ccount.blnce ( ccount.blnce < d.blnce (ccount x d (ccount)))

FORMAL DEFINITION A bsic expression in the reltionl lgebr consists of either one of the following: A reltion in the dtbse A constnt reltion Let E nd E be reltionl-lgebr expressions; the following re ll reltionl-lgebr expressions: E E E - E E x E p (E ), P is predicte on ttributes in E s (E ), S is list consisting of some of the ttributes in E x (E ), x is the new nme for the result of E

ADDITIONAL OPERATIONS We define dditionl opertions tht do not dd ny power to the reltionl lgebr, but tht simplify common queries. Set intersection Nturl join Division Assignment

SET-INTERSECTION OPERATION Nottion: r s Defined s: r s ={ t t r nd t s } Assume: r, s hve the sme rity ttributes of r nd s re comptible Note: r s = r - (r - s)

SET-INTERSECTION OPERATION - Reltion r, s: A B EXAMPLE A B 3 r s A B r s

NATURAL-JOIN OPERATION Nottion: r s Let r nd s be reltions on schems R nd S respectively. Then, r s is reltion on schem R S obtined s follows: Consider ech pir of tuples t r from r nd t s from s. If t r nd t s hve the sme vlue on ech of the ttributes in R S, dd tuple t to the result, where t hs the sme vlue s t r on r t hs the sme vlue s t s on s Exmple: R = (A, B, C, D) S = (E, B, D) Result schem = (A, B, C, D, E) r s is defined s:

NATURAL JOIN OPERATION EXAMPLE Reltions r, s: A B 4 C D b b B 3 3 D b b E r A B C D b E s r s

DIVISION OPERATION r s Suited to queries tht include the phrse for ll. Let r nd s be reltions on schems R nd S respectively where R = (A,, A m, B,, B n ) S = (B,, B n ) The result of r s is reltion on schem R S = (A,, A m ) r s = { t t R-S (r) u s ( tu r ) }

DIVISION OPERATION EXAMPLE Reltions r, s: A B B r s: A r 3 3 4 6 s

ANOTHER DIVISION EXAMPLE A B C D b b b b E 3 Reltions r, s: r s: D b E A B C r s

DIVISION OPERATION (CONT.) Property Let q r s Then q is the lrgest reltion stisfying q x s r Definition in terms of the bsic lgebr opertion Let r(r) nd s(s) be reltions, nd let S R r s = R-S (r) R-S ( ( R-S (r) x s) R-S,S (r)) To see why R-S,S (r) simply reorders ttributes of r R-S ( R-S (r) x s) R-S,S (r)) gives those tuples t in R-S (r) such tht for some tuple u s, tu r.

ASSIGNMENT OPERATION The ssignment opertion () provides convenient wy to express complex queries. Write query s sequentil progrm consisting of series of ssignments followed by n expression whose vlue is displyed s result of the query. Assignment must lwys be mde to temporry reltion vrible. Exmple: Write r s s temp R-S (r) temp R-S ((temp x s) R-S,S (r)) result = temp temp The result to the right of the is ssigned to the reltion vrible on the left of the. My use vrible in subsequent expressions.

EXAMPLE QUERIES Find ll customers who hve n ccount from t lest the Downtown nd the Uptown brnches. Query CN ( BN= Downtown (depositor ccount)) CN ( BN= Uptown (depositor ccount)) where CN denotes customer-nme nd BN denotes brnch-nme. Query customer-nme, brnch-nme (depositor ccount) temp(brnch-nme) ({( Downtown ), ( Uptown )})

EXAMPLE QUERIES Find ll customers who hve n ccount t ll brnches locted in Brooklyn city. customer-nme, brnch-nme (depositor ccount) brnch-nme ( brnch-city = Brooklyn (brnch))

VIEWS In some cses, it is not desirble for ll users to see the entire logicl model (i.e., ll the ctul reltions stored in the dtbse.) Consider person who needs to know customer s lon number but hs no need to see the lon mount. This person should see reltion described, in the reltionl lgebr, by customer-nme, lon-number (borrower lon) Any reltion tht is not of the conceptul model but is mde visible to user s virtul reltion is clled view.

VIEW DEFINITION A view is defined using the crete view sttement which hs the form crete view v s <query expression where <query expression> is ny legl reltionl lgebr query expression. The view nme is represented by v. Once view is defined, the view nme cn be used to refer to the virtul reltion tht the view genertes. View definition is not the sme s creting new reltion by evluting the query expression Rther, view definition cuses the sving of n expression;

VIEW EXAMPLES Consider the view (nmed ll-customer) consisting of brnches nd their customers. crete view ll-customer s brnch-nme, customer-nme (depositor ccount) brnch-nme, customer-nme (borrower lon) We cn find ll customers of the Perryridge brnch by writing: customer-nme ( brnch-nme = Perryridge (ll-customer))

UPDATES THROUGH VIEW Dtbse modifictions expressed s views must be trnslted to modifictions of the ctul reltions in the dtbse. Consider the person who needs to see ll lon dt in the lon reltion except mount. The view given to the person, brnch-lon, is defined s: crete view brnch-lon s brnch-nme, lon-number (lon) Since we llow view nme to pper wherever reltion nme is llowed, the person my write: brnch-lon brnch-lon {( Perryridge, L-

TUPLE RELATIONAL CALCULUS A nonprocedurl query lnguge, where ech query is of the form {t P (t) } It is the set of ll tuples t such tht predicte P is true for t t is tuple vrible, t[a] denotes the vlue of tuple t on ttribute A t r denotes tht tuple t is in reltion r P is formul similr to tht of the predicte clculus

PREDICATE CALCULUS FORMULA. Set of ttributes nd constnts. Set of comprison opertors: (e.g.,,,,,, ) 3. Set of connectives: nd (), or (v) not () 4. Impliction (): x y, if x if true, then y is true x y x v y 5. Set of quntifiers: t r (Q(t)) there exists tuple in t in reltion r such tht predicte Q(t) is true t r (Q(t)) Q is true for ll tuples t in reltion r

BANKING EXAMPLE brnch (brnch-nme, brnch-city, ssets) customer (customer-nme, customer-street, customer-city) ccount (ccount-number, brnch-nme, blnce) lon (lon-number, brnch-nme, mount) depositor (customer-nme, ccount-number) borrower (customer-nme, lon-number)

EXAMPLE QUERIES Find the lon-number, brnch-nme, nd mount for lons of over $00 {t t lon t [mount] 00} Find the lon number for ech lon of n mount greter thn $00 {t s lon (t[lon-number] = s[lon-number] s [mount] 00)} Notice tht reltion on schem [lon-number] is implicitly defined by the query