DATABASTEKNIK - 1DL116

Similar documents
DATABASE DESIGN I - 1DL300

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

INF1383 -Bancos de Dados

RELATIONAL MODEL.

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

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

Bases for Vector Spaces

Boolean Algebra. Boolean Algebra

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

Chapter 2 Finite Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata

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

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

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

Lecture 3: Equivalence Relations

Lecture Solution of a System of Linear Equation

Linear Inequalities. Work Sheet 1

1B40 Practical Skills

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

Matrix Algebra. Matrix Addition, Scalar Multiplication and Transposition. Linear Algebra I 24

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

Designing Information Devices and Systems I Discussion 8B

Overview of Today s Lecture:

CS12N: The Coming Revolution in Computer Architecture Laboratory 2 Preparation

The area under the graph of f and above the x-axis between a and b is denoted by. f(x) dx. π O

DEFINITION The inner product of two functions f 1 and f 2 on an interval [a, b] is the number. ( f 1, f 2 ) b DEFINITION 11.1.

Riemann Sums and Riemann Integrals

More on automata. Michael George. March 24 April 7, 2014

Lecture 08: Feb. 08, 2019

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?

CHAPTER 1 Regular Languages. Contents

Riemann Sums and Riemann Integrals

Homework 3 Solutions

CS 330 Formal Methods and Models

Finite Automata-cont d

Quadratic Forms. Quadratic Forms

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

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

Vectors , (0,0). 5. A vector is commonly denoted by putting an arrow above its symbol, as in the picture above. Here are some 3-dimensional vectors:

CM10196 Topic 4: Functions and Relations

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Analytically, vectors will be represented by lowercase bold-face Latin letters, e.g. a, r, q.

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Introduction to Electrical & Electronic Engineering ENGG1203

378 Relations Solutions for Chapter 16. Section 16.1 Exercises. 3. Let A = {0,1,2,3,4,5}. Write out the relation R that expresses on A.

Boolean algebra.

DIRECT CURRENT CIRCUITS

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

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!!!

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

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

Finite-State Automata: Recap

Section 6.1 INTRO to LAPLACE TRANSFORMS

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

Minimal DFA. minimal DFA for L starting from any other

4 VECTORS. 4.0 Introduction. Objectives. Activity 1

Designing Information Devices and Systems I Spring 2018 Homework 7

Jim Lambers MAT 169 Fall Semester Lecture 4 Notes

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

IST 4 Information and Logic

Things to Memorize: A Partial List. January 27, 2017

Revision Sheet. (a) Give a regular expression for each of the following languages:

Recitation 3: More Applications of the Derivative

MA 15910, Lessons 2a and 2b Introduction to Functions Algebra: Sections 3.5 and 7.4 Calculus: Sections 1.2 and 2.1

Formal Languages and Automata

The practical version

Parse trees, ambiguity, and Chomsky normal form

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

Matrices. Elementary Matrix Theory. Definition of a Matrix. Matrix Elements:

p-adic Egyptian Fractions

5.2 Exponent Properties Involving Quotients

Infinite Geometric Series

KNOWLEDGE-BASED AGENTS INFERENCE

DA 3: The Mean Value Theorem

Section 4: Integration ECO4112F 2011

Farey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University

Chapter 1: Fundamentals

Symbolic enumeration methods for unlabelled structures

Bridging the gap: GCSE AS Level

Simplifying Algebra. Simplifying Algebra. Curriculum Ready.

Harvard University Computer Science 121 Midterm October 23, 2012

Closure Properties of Regular Languages

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Combinational Logic. Precedence. Quick Quiz 25/9/12. Schematics à Boolean Expression. 3 Representations of Logic Functions. Dr. Hayden So.

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

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Chapter 6 Continuous Random Variables and Distributions

Continuous Random Variables

New data structures to reduce data size and search time

Riemann Integrals and the Fundamental Theorem of Calculus

The graphs of Rational Functions

Continuous Random Variables Class 5, Jeremy Orloff and Jonathan Bloom

Lecture 9: LTL and Büchi Automata

Introduction to Algebra - Part 2

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

IST 4 Information and Logic

MATH 144: Business Calculus Final Review

Bernoulli Numbers Jeff Morton

Read section 3.3, 3.4 Announcements:

(e) if x = y + z and a divides any two of the integers x, y, or z, then a divides the remaining integer

Transcription:

DATABASTEKNIK - DL6 Spring 004 An introductury course on dtse systems http://user.it.uu.se/~udl/dt-vt004/ Kjell Orsorn Uppsl Dtse Lortory Deprtment of Informtion Technology, Uppsl University, Uppsl, Sweden Kjell Orsorn 3//04

Introduction to Reltionl Alger Elmsri/Nvthe ch 6 Kjell Orsorn Deprtment of Informtion Technology Uppsl University, Uppsl, Sweden Kjell Orsorn 3//04

3 Query lnguges Lnguges where users cn express wht informtion to retrieve from the dtse. Ctegories of query lnguges: Procedurl Non-procedurl (declrtive) Forml ( pure ) lnguges: Reltionl lger Reltionl clculus Tuple-reltionl clculus Domin-reltionl clculus Forml lnguges form underlying sis of query lnguges tht people use. Kjell Orsorn 3//04

4 Reltionl lger Reltionl lger is procedurl lngue Opertions in reltionl lger tkes two or more reltions s rguments nd return new reltion. Reltionl lgeric opertions: Opertions from set theory: Union, Intersection, Difference, Crtesin product Opertions specificlly introduced for the reltionl dt model: Select, Project, Join It hve een shown tht the select, project, union, difference, nd crtesin product opertions form complete set. Tht is ny other reltionl lger opertion cn e expressed in these. Kjell Orsorn 3//04

Opertions from set theory Reltions re required to e union comptile to e le to tke prt in the union, intersection nd difference opertions. Two reltions R nd R is sid to e union-comptile if: R Õ D xd x...xd n nd R Õ D xd x...xd n i.e. if they hve the sme degree nd the sme domins. Kjell Orsorn 3//04

6 Union opertion The union of two union-comptile reltions R nd S is the set of ll tuples tht either occur in R, S, or in oth. Nottion: R» S Defined s: R» S = {t t Œ R or t Œ S} For exmple: R S A B» A B = A B 3 3 Kjell Orsorn 3//04

7 Difference opertion The difference etween two union-comptile sets R nd S is the set of ll tuples tht occur in R ut not in S. Nottion: R - S Defined s: R - S = {t t Œ R nd t œ S} For exmple: R S A B - A B = A B 3 Kjell Orsorn 3//04

8 Intersection The intersection of two union-comptile sets R nd S, is the set of ll tuples tht occur in oth R nd S. Nottion: R «S Defined s: R «S = {t t Œ R nd t Œ S} For exmple: R S A B «A B = A B 3 Kjell Orsorn 3//04

9 Crtesin product Let R nd S e reltions with k nd k rities resp. The crtesin product of R nd S is the set of ll possile k +k tuples where the first k components constitute tuple in R nd the lst k components tuple in S. Nottion: R S Defined s: R S = {t q t Œ R nd q Œ S} Assume tht ttriutes of r(r) nd s(s) re disjoint. (i.e. R «S = ). If ttriutes of r(r) nd s(s) re not disjoint, then renming must e used. X = Kjell Orsorn 3//04

Kjell Orsorn 3//04 0 UU - IT - UDBL Crtesin product exmple A B C D c 6 = A B C D c c 6 6

Selection opertion The selection opertor, s, selects specific set of tuples from reltion ccording to selection condition (or selection predicte) P. Nottion: s p (R) Defined s: s p (R) = {t t Œ R nd P(t) } (i.e. the set of tuples t in R tht fulfills the condition P) Where P is logicl expression (*) consisting of terms connected y: Ÿ (nd), (or), ÿ (not) nd ech term is one of: <ttriute> op <ttriute> or <constnt> where op is one of: =,, >,. <. Exmple: s SALARY>30000 (EMPLOYEE) (*) formul in propositionl clculus Kjell Orsorn 3//04

Kjell Orsorn 3//04 UU - IT - UDBL Selection exmple = A B C D 4 7 7 3 9 R s A=B Ÿ D > (R) = A B C D 4 7 9

3 Projection opertion The projection opertor, P, picks out (or projects) listed columns from reltion nd cretes new reltion consisting of these columns. Nottion: P A,A,...,Ak (R) where A, A re ttriute nmes nd R is reltion nme. The result is new reltion of k columns. Duplicte rows removed from result, since reltions re sets. Exmple: P LNAME,FNAME,SALARY (EMPLOYEE) Kjell Orsorn 3//04

Kjell Orsorn 3//04 4 UU - IT - UDBL Projection exmple = A B 3 4 C R P A,C (R) = A C = A C

Join opertor The join opertor, ƒ (lmost), cretes new reltion y joining relted tuples from two reltions. Nottion: R ƒ C S C is the join condition which hs the form A r q A s, where q is one of {=, <, >,,, }. Severl terms cn e connected s C ŸC Ÿ...C k. A join opertion with this kind of generl join condition is clled Thet join. Kjell Orsorn 3//04

Kjell Orsorn 3//04 6 UU - IT - UDBL Exmple Thet join ƒ A D = A B 6 9 7 7 C B 3 3 3 8 8 7 7 7 7 A B 6 9 7 7 C 3 8 8 B C 7 7 3 3 8 D 4 9 R ƒ A D S C 3 3 8 8 8 D 4 9 9 9 R S

7 Equijoin The sme s join ut it is required tht ttriute A r nd ttriute A s should hve the sme vlue. Nottion: R ƒ C S C is the join condition which hs the form A r = A s. Severl terms cn e connected s C ŸC Ÿ...C k. Kjell Orsorn 3//04

Kjell Orsorn 3//04 8 UU - IT - UDBL Exmple Equijoin ƒ B=C = A B 4 C D 4 d d A B 4 C D 4 9 d d d E e e e R ƒ B=C S E e e R S

9 Nturl join Nturl join is equivlent with the ppliction of join to R nd S with the equlity condition A r = A s (i.e. n equijoin) nd then removing the redundnt column A s in the result. Nottion: R * Ar,As S A r,a s re ttriute pirs tht should fulfil the join condition which hs the form A r = A s. Severl terms cn e connected s C ŸC Ÿ...C k. Kjell Orsorn 3//04

Kjell Orsorn 3//04 0 UU - IT - UDBL Exmple Nturl join ƒ B=C = A B 4 D d d A B 4 C D 4 9 d d d E e e e R * B=C S E e e R S

Kjell Orsorn 3//04 UU - IT - UDBL Composition of opertions Expressions cn e uilt y composing multiple opertions Exmple: s A=C (R S) s A=C (R S) = A B C D c 6 = A B C D c c 6 6 A B C D 6 R S =

Additionl reltionl opertions Assignment nd Renme Division Outer join nd outer union Aggregte functions (presented together with SQL) Updte opertions (presented together with SQL) (not prt of pure query lnguge) Kjell Orsorn 3//04

3 Assignment opertion The ssignment opertion ( ) mkes it possile to ssign the result of n expression to temporry reltion vrile. Exmple: temp s dno = (EMPLOYEE) result fnme,lnme,slry (temp) The result to the right of the is ssigned to the reltion vrile on the left of the. The vrile my use vrile in susequent expressions. Kjell Orsorn 3//04

4 Renming reltions nd ttriute The ssignment opertion cn lso e used to renme reltions nd ttriutes. Exmple: NEWEMP s dno = (EMPLOYEE) R(FIRSTNAME,LASTNAME,SALARY) fnme,lnme,slry (NEWEMP) Kjell Orsorn 3//04

Division opertion Suited to queries tht include the phrse for ll. Let R nd S e 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 Œ P R-S (R) Ÿ " uœs (tu ŒR)} Kjell Orsorn 3//04

6 Exmple Division opertion R S R S A c d d d d e e B 3 3 4 6 B = A e Kjell Orsorn 3//04

7 Outer join/union opertion Extensions of the join/union opertions tht void loss of informtion. Computes the join/union nd then dds tuples from one reltion tht do not mtch tuples in the other reltion to the result of the join. Fills out with null vlues: null signifies tht the vlue is unknown or does not exist. All comprisons involving null re flse y definition. Kjell Orsorn 3//04

8 Reltion lon Exmple Outer join rnch-nme Downtown Redwood Perryridge Reltion orrower customer-nme Jones Smith Hyes lon-numer -70 L-30 L-60 lon-numer -70 L-30 L- mount 3000 4000 700 Kjell Orsorn 3//04

9 Exmple Outer join cont... lon * orrower (nturl join) rnch-nme lon-numer mount customer-nme Downtown Redwood -70 L-30 3000 4000 Jones Smith lon ƒ left orrower (left outer join) rnch-nme lon-numer mount customer-nme lon-numer Downtown Redwood Perryridge -70 L-30 L-60 3000 4000 700 Jones Smith null -70 L-30 null Kjell Orsorn 3//04

30 Exmple Outer join cont... lon ƒ right orrower (nturl right outer join) rnch-nme lon-numer mount customer-nme Downtown Redwood null L-70 L-30 L- 3000 4000 null Jones Smith Hyes lon ƒ full orrower (nturl full outer join) rnch-nme lon-numer mount customer-nme Downtown Redwood Perryridge null L-70 L-30 L-60 L- 3000 4000 700 null Jones Smith null Hyes Kjell Orsorn 3//04

3 Aggregtion opertions Presented together with SQL lter Exmples of ggregtion opertions vg min mx sum count Kjell Orsorn 3//04

3 Updte opertions Presented together with SQL lter Opertions for dtse updtes re normlly prt of the DML insert (of new tuples) updte (of ttriute vlues) delete (of tuples) Cn e expressed y mens of the ssignment opertor Kjell Orsorn 3//04

33 Exmple DB schem In the following exmple we will use dtse with the following reltion schems: emps(enme, slry, dept) depts(dnme, dept#, mgr) suppliers(snme, ddr) items(inme, item#, dept) orders(o#, dte, cust) customers(cnme, ddr, lnce) supplies(snme, inme, price) includes(o#, item, quntity) Kjell Orsorn 3//04

34 Reltion lger s query lnguge Reltionl schem: supplies(snme, inme, price) Wht is the nmes of the suppliers tht supply cheese? p snme (s inme='cheese' (SUPPLIES)) Wht is the nme nd price of the items tht cost less thn $ nd tht re supplied y WALMART p inme,price (s snme='walmart' Ÿ price < (SUPPLIES)) Kjell Orsorn 3//04