Relational Model and Relational Algebra Rose-Hulman Institute of Technology Curt Clifton.

Slides:



Advertisements
Similar presentations
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
The Relational Database Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
From ER Diagrams to the Relational Model Rose-Hulman Institute of Technology Curt Clifton.
CS405G: Introduction to Database Systems Final Review.
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
Databases Illuminated
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.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Relational Data Model. A Brief History of Data Models  1950s file systems, punched cards  1960s hierarchical  IMS  1970s network  CODASYL, IDMS 
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1 Week4 Relational Model and Relational Database Constraints Relational Model Concepts.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
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.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 The Basic Relational Model.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
Advanced Relational Algebra & SQL (Part1 )
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
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 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
1 CSBP430 – Database Systems Chapter 7 - The Relational Data Model Elarbi Badidi College of Information Technology United Arab Emirates University
Lecture 03 Constraints. Example Schema CONSTRAINTS.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
The Relational Data Model & Relational Algebra
Chapter (6) The Relational Algebra and Relational Calculus Objectives
Relational Model Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3.
Module 2: Intro to Relational Model
RELATION.
Lecture # 13 (After 1st Exam)
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
376a. Database Design Dept. of Computer Science Vassar College
Chapter 2: Intro to Relational Model
Relational Integrity Constraints
Chapter 3 The Relational Database Model
The Relational Algebra and Relational Calculus
376a. Database Design Dept. of Computer Science Vassar College
02 - The Relational Database 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
Lecture 2 Relational Database
Presentation transcript:

Relational Model and Relational Algebra Rose-Hulman Institute of Technology Curt Clifton

Administrative Notes  Grading Weights  Schedule Updated

Review – ER Design Techniques  Avoid redundancy and don’t duplicate data  Don’t use entity set when attribute will do  Limit use of weak entity sets

Review – Relations  Formally Tuple: an ordered list  Each value drawn from some domain n-tuple: an ordered list of length n Relation: a set of n-tuples  Informally: Relation: a table with unique rows Rows = tuples; Columns = attributes; Values in column = domain  Database: a collection of relations

Review – Schemas  Relation schema Describes a relation RelationName (AttrName1, AttrName2,…) Or RelationName (AttrName1:type1, …)  Database schema Set of all the relation schema for the DB’s relations

Review – Converting ER Diagrams  Entity sets become relations Columns are attributes of entity set  Relationships also become relations Columns are keys of participating entity sets  Can avoid relations for many-one relationships Add key of the one to the relation of the many

Relational Model  Structure – sets of n-tuples  Basic Operations – the relational algebra Set Union, Intersection, and Difference Selection Projection Join

More On Structure  Let R(A1,A2, …, An) be a relation schema  For each tuple of the relation R… Its ith element comes from domain of Ai  Write “r(R)” for a value of R r(R)  dom(A1)  dom(A2)  …  dom(An)  Write t  r(R) for a tuple in R  Write t[K] for subtuple of t, where K is a set of attribute names

Relational Integrity Constraints  Conditions that must hold for a relation instance to be valid  Two main types Entity Integrity Referential Integrity  Need a few more terms before we can define these…

Keys, Formally  Some terms: Superkey of R: set of attributes SK of R such that no two tuples in any valid instance r(R) have the same value for SK Key of R: a minimal superkey K  Remove any attribute from K and it’s no longer a superkey Candidate key: any one of several keys Primary key: the chosen key, PK, for the relation

Entity Integrity Defined  Let DB be a database schema DB = {R1, R2, …, Rn} Where each Ri is a relation schema  Entity integrity: for every tuple t in every relation Ri of DB, t[PKi] ≠ null, where PKi is the primary key of Ri Primary keys can’t be null!

Foreign Keys  Specify relationship between tuples in different relations  Referencing relation, R1, has foreign key attributes FK  Referenced relation, R2, has primary key attributes PK  For t1  R1, t1[FK] = t2[PK] for some t2  R2  Shown with arrows…

Example – Foreign Keys  Easy to identify foreign keys when converting from ER Diagram, they encode relationships  Can also find them in relation schemas

Referential Integrity Defined  The value of the foreign key of a referencing relation can be either: the value of an existing primary key in the referenced relation, or null

Relational Model  Structure – sets of n-tuples satisfying Entity Integrity Referential Integrity  Basic Operations – the relational algebra Set Union, Intersection, and Difference Selection Projection Join

What is an “Algebra”?  Name from Muhammad ibn Musa al- Khwarizmi’s (780–850) book al-jabr About arithmetic of variables  An Algebra includes Operands – variables or values Operators – symbols denoting operations

Relational Algebra  A formal model for SQL  Operands Relations Variables  Operators Formal analogues of DB operations

Basic Set Operators  Intersection R1  R2 All tuples that are in both R1 and R2  Union R1  R2 Any tuple that is in either R1 or R2 (or both)  Difference R1 - R2 All tuples that are in R1 but are not in R2  R1 and R2 must be compatible – attribute types match

Selection,   For picking rows out of a relation  R1   C (R2) C is a boolean condition R1 and R2 are relations R1 gets every tuple of R2 that satisfies C  Selection is commutative  C1 (  C2 (R2) ) =  C2 (  C1 (R2) ) =  C1^C2 (R2)

Projection,   For picking columns out of a relation  R1   L (R2) L is a list of attribute names from R2’s schema R1 and R2 are relations Attributes of R1 are given by L R1 gets every tuple of R2 but just attributes from L  Is Projection commutative?  L1 (  L2 (R2) ) =?  L2 (  L1 (R2) )

Product  Combining tables without matching  R  R1  R2 R1 and R2 are relations Pair every tuple from R1 with every tuple from R2 R gets every attribute of R1 and every attribute of R2  Can use R1.A naming convention to avoid collisions  If R1 has 10 rows and R2 has 42, how many in R?

Theta-Join  Combining tables with matching  R1 and R2 are relations C is a boolean expression over attributes of R1 and R2 Pair every tuple from R1 with every tuple from R2 where C is true R gets every attribute of R1 and every attribute of R2  If R1 has 10 rows and R2 has 42, how many in R?

Equijoin  A theta-join using an equality comparison  Really just a $5 word, but you might see it

Natural Join  Joins two relations by: Equating attributes of the same name Projecting out one copy of each shared attribute  R  R1 * R2

Dangling Tuple Problem  Suppose DEPT_LOCATION had no entry for Houston  Consider: R  DEPARTMENT * DEPT_LOCATIONS  What happens to Headquarters?

Outer Joins  Solve the dangling tuple problem  If a tuple would be dropped by the join, then include it and use null for the other attributes  Shown as a bow tie with “wings” Wings point to relation whose tuples must appear

Renaming   R1(A1,…,An) (R2) Rename R2 to R1 Rename attributes to A1, …, An  Usually just play fast and loose: R1   A1,…,An (R2), or R1(A1, …, An)  R2

Combining Expressions  Nesting: R   L (  C (R1  R2)) Work inside out like you’re used to  Sequencing: Rc  R1  R2 Rs   C (Rc)) R   L (Rs)

Homework Problem 6.18  Parts a–d and g  Begin in class, may work in groups of 2–3 Please note your partners on the sheet