Database Group, Georgia Tech 1 Relational Model The Relational Model - theoretical foundation.

Slides:



Advertisements
Similar presentations
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Advertisements

Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
D ATABASE S YSTEMS I R ELATIONAL A LGEBRA. 22 R ELATIONAL Q UERY L ANGUAGES Query languages (QL): Allow manipulation and retrieval of data from a database.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Relational Algebra Indra Budi Fakultas Ilmu Komputer UI 2 n Basic Relational Operations: l Unary Operations  SELECT   PROJECT 
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
1 Classical Database Development Methodology. 2 Area of Application Perspective Work-Processes Guidelines for Work-Processes in the development of the.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
D ATABASE S YSTEMS I A DMIN S TUFF. 2 Mid-term exam Tuesday, Oct 2:30pm Room 3005 (usual room) Closed book No cheating, blah blah No class on Oct.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Lesson II The Relational Model © Pearson Education Limited 1995, 2005.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
1 SQL SQL - intergalactic dataspeak [Stonebraker].
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Rutgers University Relational Calculus 198:541 Rutgers University.
Database Group, Georgia Tech 1 SQL SQL - intergalactic dataspeak [Stonebraker]
Databases Illuminated
Relational Algebra.  Introduction  Relational Algebra Operations  Projection and Selection  Set Operations  Joins  Division  Tuple Relational Calculus.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Database Group, Georgia Tech 1 Normalization. Database Group, Georgia Tech 2 Normalization What it’s all about Given a relation, R, and a set of functional.
Relational Query Languages. Languages of DBMS  Data Definition Language DDL  define the schema and storage stored in a Data Dictionary  Data Manipulation.
FEN  Concepts and terminology  Operations (relational algebra)  Integrity constraints The relational model.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
Relational Calculus R&G, Chapter 4. Relational Calculus Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). Calculus.
Relational Calculus CS 186, Spring 2005, Lecture 9 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
The Relational Algebra and Calculus
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Database Group, Georgia Tech 1 Relational Model The Relational Model - theoretical foundation.
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
CSE202 Database Management Systems
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Fundamental of Database Systems
Relational Algebra - Part 1
Relational Calculus Chapter 4, Part B
The Relational Algebra and Relational Calculus
Chapter 2: Intro to Relational Model
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
Relational Database Models
Relational Calculus.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 6: Formal Relational Query Languages
Chapter 2: Intro to Relational Model
Relational Algebra & Calculus
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Relational Calculus Chapter 4, Part B
Presentation transcript:

Database Group, Georgia Tech 1 Relational Model The Relational Model - theoretical foundation

Database Group, Georgia Tech 2 Relational Model The Relational Model data structures constraints operations –algebra (ISBL) –tuple calculus (QUEL, SQL) –domain calculus (QBE) views

Database Group, Georgia Tech 3 Relational Model Data Structures let D 1, D 2, D 3,..., D n be sets (not necessarily distinct) of atomic values relation, R, defined over D 1, D 2, D 3,..., D n is a subset of the set of ordered n- tuples {<d 1, d 2, d 3,..., d n | d i  D i, i=1,...,n}; D 1, D 2, D 3,..., D n are called domains the number, n, is the degree of the relation (unary, binary, ternary, n-ary). the number of tuples, |R|, in R is called the cardinality of R if D 1, D 2, D 3,..., D n are finite then there are 2 | D1 |  | D2 | ...  | Dn | possible relation states

Database Group, Georgia Tech 4 Relational Model Data Structures an attribute name refers to a position in a tuple by name rather than position an attribute name indicate the role of a domain in a relation attribute names must be unique within relations by using attribute names we can forget the ordering of field values in tuples a relation definition includes the following R( A 1 :D 1, A 2 :D 2,..., A n :D n )

Database Group, Georgia Tech 5 Relational Model Constraints keys primary keys entity integrity referential integrity RESERVATION FLT#DATECUST# FLT-SCHEDULE FLT# CUSTOMER CUST#CUST-NAME p p

Database Group, Georgia Tech 6 Relational Model CUSTOMER cust# first middle last phone# street city state zip RESERVATION flt# date cust# seat# check-in-status ticket# AIRPORT airportcode name city state FLT-SCHEDULE flt# airline dtime from-airportcode atime to-airportcode miles price FLT-WEEKDAY flt# weekday AIRPLANE plane# plane-type total-#seats FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 7 Relational Model Operations classes of relational DMLs: –relational algebra (ISBL) –tuple calculus (QUEL, SQL) –domain calculus (QBE) a relational DML with the same “retrieval power” as the relational algebra is said to be relationally complete all relational DMLs have syntax for: –change (insert, delete, update) –queries (retrieval)

Database Group, Georgia Tech 8 Relational Model Operations - insert, delete, update constructs for insertion are very primitive: INSERT INTO FLT-SCHEDULE VALUES (“DL212”, “DELTA”, , “ATL”, , ”CHI”, 650, ); INSERT INTO FLT-SCHEDULE VALUES (FLT#:“DL212”, AIRLINE:“DELTA”); FLT-SCHEDULE flt# airline dtime from-airportcode atime to-airportcode miles price

Database Group, Georgia Tech 9 Relational Model Operations - insert, delete, update “insert into FLT-INSTANCE all flights scheduled for Thursday, 9/10/98” INSERT INTO FLT-INSTANCE(flt#, date) (SELECT S.flt#, FROM FLT-SCHEDULE S, FLT-WEEKDAY D WHERE S.flt#=D.flt# AND weekday=“TH”); interesting only because it involves a query FLT-SCHEDULE flt# airline dtime from-airportcode atime to-airportcode miles price FLT-WEEKDAY flt# weekday FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 10 Relational Model Operations - insert, delete, update constructs for deletion are very primitive: “delete flights scheduled for Thursdays” DELETE FROM FLT-WEEKDAY WHERE weekday=“TH”; interesting only because it involves a query FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 11 Relational Model Operations - insert, delete, update constructs for update are very primitive: “update flights scheduled for Thursdays to Fridays” UPDATE FLT-WEEKDAY SET weekday=“FR” WHERE weekday=“TH”; interesting only because it involves a query FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 12 Relational Model Relational Algebra the Relational Algebra is procedural; you tell it how to construct the result it consists of a set of operators which, when applied to relations, yield relations (closed algebra) R  Sunion R  Sintersection R \ Sset difference R  SCartesian product  A1, A2,..., An (R)projection  expression (R)selection R Snatural join R   Stheta-join R  Sdivideby  [ A 1 B 1,.., An Bn ]rename

Database Group, Georgia Tech 13 Relational Model Selection “find (flt #, weekday ) for all flights scheduled for Mondays”  weekday=MO ( FLT-WEEKDAY ) the expression in  expression ( R ) involves: operands: constants or attribute names of R comparison operators: Š   ° = logical operators:  nesting: ( ) FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 14 Relational Model Projection “find flt # for all flights scheduled for Mondays  flt# (  weekday=MO ( FLT-WEEKDAY )) the attributes in the attribute list of  A1, A2,..., An ( R ) must be attributes of the operand R FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 15 Relational Model Union “find the flt# for flights that are schedule for either Mondays, or Tuesdays, or both”   flt# (  weekday=MO ( FLT-WEEKDAY ))   flt# (  weekday=TU ( FLT-WEEKDAY )) the two operands must be "type compatible" FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 16 Relational Model Intersection “find the flt# for flights that are schedule for both Mondays and Tuesdays”   flt# (  weekday=MO ( FLT-WEEKDAY ))   flt# (  weekday=TU ( FLT-WEEKDAY )) the two operands must be "type compatible" FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 17 Relational Model Set Difference “find the flt# for flights that are scheduled for Mondays, but not for Tuesdays”   flt# (  weekday=MO ( FLT-WEEKDAY ))  \   flt# (  weekday=TU ( FLT-WEEKDAY )) the two operands must be "type compatible" Note: R  S = R \ ( R \ S ) FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 18 Relational Model Cartesian Product “make a list containing (flt#, date, cust#) for DL212 on 9/10, 98 for all customers in Roswell that are not booked on that flight” (  cust# (  city=ROSWELL ( CUSTOMER ))    flt#,date (  flt#=DL212  date= ( FLT-INSTANCE )))  \  flt#,date,cust# (RESERVATION) CUSTOMER cust# first middle last phone# street city state zip RESERVATION flt# date cust# seat# check-in-status ticket# FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 19 Relational Model Natural Join “make a list with complete flight instance information” FLT-INSTANCE FLT-WEEKDAY natural join joins relations on attributes with the same names all joins can be expressed by a combination of primitive operators:  FLT-INSTANCE.flt#, date, weekday, #avail-seats (  FLT-INSTANCE.flt#=FLT-WEEKDAY.flt# ( FLT-INSTANCE  FLT-WEEKDAY )) FLT-WEEKDAY flt# weekday FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 20 Relational Model  -join “make a list of pairs of ( FLT#1, FLT#2) that form possible connections”  fl1, flt# ((  [flt#  fl1, from-airportcode da1,dtime dt1, to-airportcode aa1, atime at1, date d1] ( FLT-SCHEDULE FLT-INSTANCE )) d1=date   aa1=from-airportcode  at1< dtime ( FLT-SCHEDULE FLT-INSTANCE )) the  -operators: Š   ° = FLT-SCHEDULE flt# airline dtime from-airportcode atime to-airportcode miles price FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 21 Relational Model Divideby “list the cust# of customers that have reservations on all flight instances”  flt#, date, cust# RESERVATION   flt#, date ( FLT-INSTANCE ) RESERVATION flt# date cust# seat# check-in-status ticket# FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 22 Relational Model R  S R UNION S R  S R INTERSECT S R \ S R MINUS S  A1, A2,..., An (R) R[A1, A2,..., An]  expression (R) R WHERE EXPRESSION R  S R JOIN S (no shared attributes) R S R JOIN S (shared attributes) R   Svia selection from  R  S R DIVIDEBY S  [ A1 B1,..., An Bn ] (R) R[A1 B1,.., An Bn] ISBL - an example algebra

Database Group, Georgia Tech 23 Relational Model Features of ISBL the Peterlee Relational Test Vehicle, PRTV, has a query optimizer for ISBL Naming results: T = R JOIN S Lazy evaluation: T = N!R JOIN N!S LIST T 2-for-1 JOIN: –Cartesian product if no shared attribute names –natural join if shared attribute names ISBL is relationally complete !

Database Group, Georgia Tech 24 Relational Model ISBL - an example query “make a list of pairs of ( FLT#1, FLT#2) that form possible connections” LIST ((( FLT-SCHEDULE JOIN FLT-INSTANCE ) [ FLT#  FL1, FROM-AIRPORTCODE DA1,DTIME DT1, TO- AIRPORTCODE AA1, ATIME AT1, DATE D1 ]) JOIN ( FLT-SCHEDULE JOIN FLT-INSTANCE ) WHERE D1=DATE  AA1=FROM-AIRPORTCODE  AT1< DTIME )[ FL1, FLT# ] FLT-SCHEDULE flt# airline dtime from-airportcode atime to-airportcode miles price FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 25 Relational Model Relational Calculus the Relational Calculus is non- procedural. It allows you to express a result relation using a predicate on tuple variables (tuple calculus): { t | P(t) } or on domain variables (domain calculus): { | P( ) } you tell the system which result you want, but not how to construct it

Database Group, Georgia Tech 26 Relational Model Tuple Calculus query expression: { t | P(t) } where P is a predicate built from atoms range expression: t  R denotes that t is a member of R ; so does R(t) attribute value: t.A denotes the value of t on attribute A constant: c denotes a constant atoms: t  R, r.A  s.B, or r.A  c comparison operators: Š  ° = predicate: an atom is a predicate; if P 1 and P 2 are predicates, so are ¬( P 1 ) and ( P 1 ), P 1  P 2, P 1  P 2, and P 1  P 2 if P(t) is a predicate, t is a free variable in P, and R is a relation then  t  R  (P(t)) and  t  R (P(t) ) are predicates

Database Group, Georgia Tech 27 Relational Model Tuple Calculus { r |  ( r  CUSTOMER } is infinite, or unsafe a tuple calculus expression { r | P(r) } is safe if all values that appear in the result are from Dom( P ), which is the set of values that appear in P itself or in relations mentioned in P CUSTOMER cust# first middle last phone# street city state zip

Database Group, Georgia Tech 28 Relational Model Selection “find ( FLT#, WEEKDAY ) for all flights scheduled for Mondays { t | FLT-WEEKDAY (t)  t. WEEKDAY=MO} FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 29 Relational Model Projection “find FLT# for all flights scheduled for Mondays { t.FLT# | FLT-WEEKDAY (t)  t. WEEKDAY = MO} FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 30 Relational Model Union “find the FLT# for flights that are schedule for either Mondays, or Tuesdays, or both”  { t.FLT# | FLT-WEEKDAY (t)  (t. WEEKDAY=MO  t.WEEKDAY=TU)} FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 31 Relational Model Intersection “find the FLT# for flights that are schedule for both Mondays and Tuesdays”  { t.FLT# | FLT-WEEKDAY (t)  t. WEEKDAY=MO   s  FLT-WEEKDAY (s)  t.FLT#=s.FLT#  s.WEEKDAY=TU ) } FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 32 Relational Model Set Difference “find the FLT# for flights that are scheduled for Mondays, but not for Tuesdays”  { t.FLT# | FLT-WEEKDAY (t)  t. WEEKDAY=MO   ((  s) ( FLT- WEEKDAY (s)  t.FLT#=s.FLT#  s.WEEKDAY=TU))} FLT-WEEKDAY flt# weekday

Database Group, Georgia Tech 33 Relational Model Cartesian Product {s. FLT#, s. DATE, t.CUST# | FLT-INSTANCE (s)  CUSTOMER (t)  t. CITY=ROSWELL  s.FLT#=DL212  s. DATE=    r  FLT-INSTANCE (r)   r ° s  r. FLT#= s. FLT#   r. DATE= s. DATE  r. CUST#= t. CUST# )} “make a list containing (FLT#, DATE, CUST#) for DL212 on 9/10, 98 for all customers in Roswell that are not booked on that flight” CUSTOMER cust# first middle last phone# street city state zip RESERVATION flt# date cust# seat# check-in-status ticket# FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 34 Relational Model Natural Join “make a list with complete flight instance information” { s. FLT#, s. WEEKDAY, t. DATE, t.PLANE#, t. #AVAIL- SEATS | FLT-WEEKDAY (s)  FLT-INSTANCE (t)  s. FLT# =t. FLT# } FLT-WEEKDAY flt# weekday FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 35 Relational Model  -join “make a list of pairs of ( FLT#1, FLT#2) that form possible connections” { s. FLT#, t.FLT # | FLT-SCHEDULE (s)  FLT- SCHEDULE (t)  ((  u)(  v) FLT-INSTANCE (u)  FLT-INSTANCE (v)  u.FLT #= s.FLT #  v.FLT #= t.FLT #  u.DATE = v.DATE  s.TO- AIRPORTCODE = t.FROM-AIRPORTCODE  s.ATIME < t.DTIME ) } FLT-SCHEDULE flt# airline dtime from-airportcode atime to-airportcode miles price FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 36 Relational Model Divideby “list the CUST# for customers that have reservations on all flight instances” { s.CUST # | RESERVATION (s)  ((  t) FLT- INSTANCE (t) ((  r) RESERVATION (r)  r.FLT #=t.FLT #  r.DATE =t.DATE  r.CUST #=s.CUST #))} RESERVATION flt# date cust# seat# check-in-status ticket# FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 37 Relational Model QUEL - an example tuple calculus “make a list of pairs of ( FLT#1, FLT#2) that form possible connections” range s is FLT-SCHEDULE range t is FLT-SCHEDULE range u is FLT-INSTANCE range v is FLT-INSTANCE retrieve into CON ( s. FLT#, t. FLT# ) where u. FLT# =s. FLT# and v. FLT# =t. FLT# and u. DATE =v. DATE and s. TO- AIRPORTCODE =t. FROM-AIRPORTCODE and s. ATIME < t. DTIME; FLT-SCHEDULE flt# airline dtime from-airportcode atime to-airportcode miles price FLT-INSTANCE flt# date plane##avail-seats

Database Group, Georgia Tech 38 Relational Model QBE - Projection “find FLT# for all flights scheduled for Mondays FLT-WEEKDAY FLT# WEEKDAY P. =MONDAY

Database Group, Georgia Tech 39 Relational Model QBE - Union “find the FLT# for flights that are schedule for either Mondays, or Tuesdays, or both”  FLT-WEEKDAY FLT# WEEKDAY P.MONDAY P.TUESDAY

Database Group, Georgia Tech 40 Relational Model QBE - Intersection “find the FLT# for flights that are schedule for both Mondays and Tuesdays”  FLT-WEEKDAY FLT# WEEKDAY P._SXMONDAY _SXTUESDAY

Database Group, Georgia Tech 41 Relational Model QBE - Set Difference “find the FLT# for flights that are scheduled for Mondays, but not for Tuesdays”  FLT-WEEKDAY FLT# WEEKDAY P._SXMONDAY _SXTUESDAY 

Database Group, Georgia Tech 42 Relational Model QBE - Cartesian Product “make a list containing (FLT#, DATE, CUST#) for DL212 on 9/10, 98 for all customers in Roswell that are not booked on that flight” RESERVATION FLT#DATECUST# _F_D_C  FLT-INSTANCE FLT#DATE #AVAIL- SEATS P._FP._D _F _DDL212 CUSTOMER CUST#CUST-NAMECITY P._CROSWELL

Database Group, Georgia Tech 43 Relational Model QBE - Natural Join “make a list with complete flight instance information” FLT-WEEKDAY FLT# WEEKDAY FLT-INSTANCE FLT#DATE #AVAIL- SEATS P._SX_SXP.

Database Group, Georgia Tech 44 Relational Model QBE  -join “make a list of pairs of ( FLT#1, FLT#2) that form possible same day connections” CONDITION _AT < _DT FLT-SCHEDULE FLT# AIRLINE FROM- AIRPORT CODE DTIMEPRICEATIME TO- AIRPORT CODE P._SX_A_AT FLT-INSTANCE FLT#DATE#SEATS _SX _SY _D FLT-SCHEDULE FLT# AIRLINEDTIMEPRICEATIME P._SY_A_DT FROM- AIRPORT CODE TO- AIRPORT CODE

Database Group, Georgia Tech 45 Relational Model Views relational query languages are closed, i.e., the result of a query is a relation a view is a named result of a query a view is a snapshot relation views can be used in other queries and view definitions queries on views are evaluated by query modification some views are updatable some views are not updatable more on views when we look at SQL