1 The Relational Data Model, Relational Constraints, and The Relational Algebra.

Slides:



Advertisements
Similar presentations
Chapter 6 The Relational Algebra
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Relational Model and Relational Algebra Rose-Hulman Institute of Technology Curt Clifton.
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
Database Architecture The Relational Database Model.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
The Relational Algebra and Calculus. Relational Algebra Overview Relational algebra is the basic set of operations for the relational model These operations.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
1 Lecture 04 The relational data Model, Relational Constraints 1.
Relational Model Session 6 Course Name: Database System Year : 2012.
The Relational Data Model 1.Relational Model Concepts 2.Characteristics of Relations 3.Relational Integrity Constraints 3.1Key Constraints 3.2Entity Integrity.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
Topic 5 The Relational Data Model and Relational Database Constraints Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
The Relational Data Model and Relational Database Constraints
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Chapter 6 The Relational Data Model and the Relational Algebra.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
The Relational Algebra. 1 RELATIONAL ALGEBRARELATIONAL ALGEBRA 2 UNARY RELATIONAL OPERATIONS * SELECT OPERATIONSELECT OPERATION * PROJECT OPERATIONPROJECT.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
The Relational Algebra and Calculus
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Relational Model E.F. Codd at IBM 1970 Chapter 3 (ed. 7 – Chap. 5)
1 CSBP430 – Database Systems Chapter 7 - The Relational Data Model Elarbi Badidi College of Information Technology United Arab Emirates University
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Chapter 6 The Relational Algebra Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
The Relational Data Model & Relational Algebra
Database Systems Chapter 6
Chapter (6) The Relational Algebra and Relational Calculus Objectives
The Relational Algebra and Calculus
Module 2: Intro to Relational Model
Chapter # 6 The Relational Algebra and Calculus
Fundamental of Database Systems
Database Design The Relational Model Text Ch5
The Relational Algebra and Relational Calculus
Chapter 2: Intro to Relational Model
376a. Database Design Dept. of Computer Science Vassar College
Chapter 4 The Relational Algebra and Calculus
The Relational Data Model
Chapter (7) The relational Data Model, Relational Constraints, and the Relational Algebra Objectives Describe the basic principals of the relational model.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
RELATIONAL DATA MODEL - 1
Presentation transcript:

1 The Relational Data Model, Relational Constraints, and The Relational Algebra

2 Contents Relational Model Concepts Relational Constraints and Relational Database Schemas Basic Relational Algebra Operations Additional Relational Operations

3 Relational Model Concepts The Relational model represents the database as a collection of relations Relation is thought of as “table” of values, where each row represents a collection of related data values. Table name and Column names are used to help in interpreting the meaning of the values in each row. In the formal relational model: row – tuple, column header – attribute, table – relation, type of values that can appear in each column – domain. Domains: A domain D is a set of atomic values. A domain is given a name, data type and format. Units can also be given to a domain. R (A1, A2, A3…, An) D = dom (Ai) R – name of the relation n – degree of a relation

4 Example STUDENT (Name, IRD, HomePhone, Address, OfficePhone, Age, GPA) What is the relation name? What is the degree of the relation? What are the attributes? List each dom(Ai). A relation r (or relation state ) of the relation schema R(A1, A2,..., An), also denoted by r(R), is a set of n tuples r = {t1, t2,..., tk}. Each n-tuple t is an ordered list of n values t =, where each value vi is an element of dom(Ai) or is a special null value. Possible for several attributes to have the same domain. The attributes indicate different roles or interpretations for the domain.

5 Characteristics of Relations Ordering of tuples in a relation » No Ordering of values within a tuple » Yes Values in the tuples » is an atomic value » composite and multivalued attributes are not allowed How to represent multi-valued attributes? » by separate relation How to represent composite attributes? » only by their simple component attributes. NULL » Value unknown » May not apply » exists but not available

6 Relational Model Notations Q, R, S denote relation names q, r, s denote relation states t, u, v denote tuples STUDENT indicates the current set of tuples STUDENT(Name, IRD,...) refers only to the relation schema An attribute can be qualified with a relation name, such as R.A

7 Relational Constraints and Relational Database Schemas Domain Constraints Key Constraints and Constraints on Null Relational Databases and Relational Database Schemas Entity Integrity, Referential Integrity and Foreign Keys Domain Constraints Domain constraints specify that the value of each attribute ‘A’ must be an atomic value from the domain. Data types are usually associated with domains Examples Subrange

8 Key Constraints and Constraints on Null No two tuples can have the same values for all their attributes. Superkey - a set of attributes such that for any two distinct tuples t1 and t2 » t1[SK] != t2[SK] » Any set of attributes satisfying the above is a superkey The superkey specifies a uniqueness constraint on the tuples A key K of a relation schema R is a superkey of R with the additional property that removing any of the attributes from K leaves a set of attributes that is not a superkey. A relation schema may have more than one key. Each of the keys is called a candidate key. Typically one candidate key is designated the primary key.

9 Relational Databases and Relational Database Schemas

10 Entity Integrity The primary key is used to identify individual tuples. The entity integrity constraint states that no primary key value can be null. Key constraints and entity constraints are specified on individual relations. Referential Integrity The referential integrity constraint is specified between two relations. It is used to maintain consistency among tuples of the two relations. Informally, it states that a tuple in one relation that refers to another relation must refer to an existing tuple in that relation. Example

11 Foreign Keys A set of attributes FK in relation schema R1 is a foreign key of R1 that references relation R2 if it satisfies these conditions: » The attributes of FK have the same domain(s) as the primary key attributes PK of R2 » A value of FK in a tuple t1 of the current state r1(R1) either occurs as a value of PK for some tuple t2 in the current state r2(R2) or is null. The attributes FK are said to refer to the relation R2. From (2), we have t1[FK] = t2[PK].

12

13 Basic Relational Algebra Operations Need a set of operations Relational algebra Retrieval can be from one relation or more than one relation Result is a relation Relational algebra expression – sequence of relational algebra operations Operations divided into two groups » Set operations from mathematical set theory: UNION, INTERSECTION, SET DIFFERENCE and CARTESIAN PRODUCT. » Operations developed for relational databases: SELECT, PROJECT, JOIN SELECT: σ (R) σDNO =4(EMPLOYEE) σSALARY >30000(EMPLOYEE) σ(DNO =4 AND SALARY>25000) OR DNO=5 AND SALARY>30000)(EMPLOYEE)

14 SELECT is commutative σ (σ (R)) = σ (σ (R)) A cascade of SELECTs can be combined into a single SELECT σ (σ (...(σ (R)) = σ AND AND.. AND (R) PROJECT: Selects some attributes from a relation Π (R) The result is a relation having only the attributes in the attribute list. Order of attributes is the order. The degree of the relation is the number of attributes in the list. Duplicates are removed. Π (Π (R)) = Π (R) » As long as contains the attributes in Commutativity does not hold for PROJECT. Example: ΠLNAME, FNAME, SALARY(EMPLOYEE) ΠSEX, SALARY(EMPLOYEE)

15 Sequences of Operations Operations can be » Nested » Applied one (or a few) at a time, creating intermediate results Example » ΠFNAME, LNAME, SALARY (σDNO=5(EMPLOYEE)) or » DEP5_EMPS ← σDNO=5(EMPLOYEE) » RESULT ← ΠFNAME, LNAME, SALARY(DEP5_EMPS) RENAME: ρS (R) ρ(B1, B2,..., Bn) (R) ρS(B1, B2,..., Bn) (R) ρ (rho) – RENAME Operator S is the new relation name. B1, B2,..., Bn are the new attribute names.

16 Set Theoretic Operations UNION » R ∪ S Includes all tuples that are in R or in S or in both INTERSECTION » R ∩ S Includes every tuple that is simultaneously in both R and S SET DIFFERENCE » R - S » Includes all tuples that are in R but not is S UNION and INTERSECTION are commutative » R ∪ S = S ∪ R » R ∩ S = S ∩ R UNION and INTERSECTION are associative » R ∪ (S ∪ T) = (R ∪ S) ∪ T » R ∩ (S ∩ T) = (R ∩ S) ∩ T SET DIFFERENCE is not commutative » R - S != S - R Must be union compatible » Have the same degree n » dom(Ai) = dom(Bi) for all i

17 DEPT3_EMPS  σDNO=5(EMPLOYEE) RESULT1  ΠSSN(DEP5_EMPS) RESULT2  ΠSUPERSSN(DEP5_EMPS) RESULT  RESULT1 U RESULT2

18

19 CARTESIAN PRODUCT Also called CROSS PRODUCT R X S R(A1, A2,..., An) X S(B1, B2,..., Bm) = Q(A1, A2,..., An, B1, B2,..., Bm) Attributes are in the order given above. Q has one tuple for each combination of tuples in R and S. n + m attributes If R has x tuples and S has y tuples » x * y tuples Meaningless unless used with other operations

20 Example: Retrieve for each female employee a list of the names of her dependents.

21 JOIN Used to combine related tuples from two relations into single tuples Denoted by R S Retrieve the name of the manager of each department.

22 Example

23

24

25