CSC 240 (Blum)1 Relational Math. CSC 240 (Blum)2 Relational Algebra The rules for combining one or more numbers (or symbols standing in for numbers) to.

Slides:



Advertisements
Similar presentations
Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple.
Advertisements

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
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.
Relational Algebra Dashiell Fryer. What is Relational Algebra? Relational algebra is a procedural query language. Relational algebra is a procedural query.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Relational Algebra.
Databases Illuminated
RELATIONAL ALGEBRA Objectives
Concepts of Database Management, Fifth Edition
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
CSC 240 (Blum)1 Joins. CSC 240 (Blum)2 Relational algebra Recall relational algebra was the study of actions that are performed on one or more tables.
Copyright © Curt Hill The Relational Algebra What operations can be done?
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 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.
Concepts of Database Management Seventh Edition
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Using Special Operators (LIKE and IN)
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
CSC 240 (Blum)1 Forms and Importing Data in Access.
Relational Algebra (Chapter 7)
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports.
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
The Relational Algebra and Calculus
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
CS424 Relational Data Manipulation Relational Data Manipulation Relational tables are sets. Relational tables are sets. The rows of the tables can be considered.
CSC 240 (Blum) 1 Relational Math. Relational Algebra CSC 240 (Blum) 2 The rules for combining one or more numbers (or symbols standing in for numbers)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
1 Geog 357 – Introduction to GIS The Relational Language.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
Relational Algebra MBAD 613 R. Nakatsu. Relational Data Manipulation Language Query-by-Example; Query-by-Form Transform-Oriented Languages Relational.
Advanced Relational Algebra & SQL (Part1 )
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
1 2 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra.
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems.
April 20022CS3X1 Database Design Relational algebra John Wordsworth Department of Computer Science The University of Reading Room.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
LECTURE THREE RELATIONAL ALGEBRA 11. Objectives  Meaning of the term relational completeness.  How to form queries in relational algebra. 22Relational.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Ritu CHaturvedi Some figures are adapted from T. COnnolly
COMP3017 Advanced Databases
Chapter 2: Relational Model
Relational Algebra.
Lecture 2 The Relational Model
Relational Math CSC 240 (Blum).
The Relational Algebra and Relational Calculus
Joins CSC 240 (Blum).
Data Manipulation using Relational Algebra
Schedule Today: Next And then Relational Algebra.
Relational Database Operators
Presentation transcript:

CSC 240 (Blum)1 Relational Math

CSC 240 (Blum)2 Relational Algebra The rules for combining one or more numbers (or symbols standing in for numbers) to obtain another number is called algebra. For example, the rules for combining one or more Boolean variables (expressions which are either true or false) to obtain another Boolean is called Boolean algebra. The rules for combining one or more relations to obtain another relation is called relational algebra.

CSC 240 (Blum)3 Operations The specific ways of combining elements are known as operations. –E.g. addition is an algebraic operation –E.g. ANDing is a Boolean operation Operations are called unary if they act on one element and binary if they act on two elements. –E.g square root is a unary algebraic operation. –E.g. addition is a binary algebraic operation.

CSC 240 (Blum)4 Relation  Table Relational algebra sounds so abstract. –Recall a representation of a relation is a table. –So relational algebra means that we do stuff to tables and get other tables out. A relational database is made of tables. –Relational algebra tells us how to operate on tables. –That is, relational algebra tells us what a Data Manipulation Language (DML) should do.

CSC 240 (Blum)5 Synonym Recall our old synonyms –Table  Relation  File –Row  Tuple  Record –Column  Attribute  Property  Field A new synonym pair is –Condition  Predicate –A condition is a Boolean, an expression that is true or false, e.g. Salary > or Name=“Smith”

CSC 240 (Blum)6 Selection/Restriction A selection (a.k.a. restriction) picks out those rows from a table that meet some condition. Example: Let us select from the Customer table those people who are from PA.  predicate ( R )

CSC 240 (Blum)7 Selection Example: Actors Only (Design) Customer.* refers to all of the columns. The condition (predicate) selecting out particular rows.

CSC 240 (Blum)8 Selection Example: PA Only (DataSheet)

CSC 240 (Blum)9 Selection Example: PA Only (SQL) Condition

CSC 240 (Blum)10 Condition can be compound. The selection condition may be a compound condition. –ConditionA AND ConditionB –ConditionA OR ConditionB Example: Let us select from the Customer table those people who from Philadelphia and from PA. (There are other Philadelphias, e.g. in Mississippi)

CSC 240 (Blum)11 Added Some New Customers

CSC 240 (Blum)12 Selection Example: Philadelphia AND PA (Design) ANDed conditions are entered on the same line.

CSC 240 (Blum)13 Selection Example: Philadelphia AND PA (DataSheet)

CSC 240 (Blum)14 Selection Example: Philadelphia AND PA (SQL) ANDed conditions

CSC 240 (Blum)15 Selection Example: Customers from PA or NJ (Design) ORed conditions are entered on separate lines.

CSC 240 (Blum)16 Selection Example: Customers from PA or NJ (DataSheet)

CSC 240 (Blum)17 Selection Example: Customers from PA or NJ (SQL) ORed Conditions

CSC 240 (Blum)18 Projection The projection operator picks out a set of columns that will belong to the resulting table. –Recall the concept of views in which certain fields would be hidden from certain users. Example: Let us project from the Customer table the first and last names.  column1,column2,… ( R )

CSC 240 (Blum)19 Projection Example: Customer’s first and last names (Design) Choose columns and check to show them.

CSC 240 (Blum)20 Projection Example: Customer’s first and last names (DataSheet)

CSC 240 (Blum)21 Projection Example: Customer’s first and last names (SQL) Columns that will appear.

CSC 240 (Blum)22 Union Compatible Think of the records in a table as elements of a set. If two sets have the same sorts of records, that is, the same fields in the same order or minimally the same type fields in the same order, then the sets are said to be union-compatible. Then you can consider forming –The union of the two sets –The intersection of the two sets –The set difference

CSC 240 (Blum)23 A Simpsons Database

CSC 240 (Blum)24 Union The union of set A and set B contains all of the elements of set A as well as all of the elements of set B –If an element belongs to set A and set B, the union contains only one copy of it. Example: let us make a table containing all of the names from the Character and RealPerson tables  FirstName,LastName (Character)   FirstName,LastName (RealPerson)

CSC 240 (Blum)25 Union Example: Character and RealPerson names Step 1 would be to create union-compatible tables using projection. Step 2 would be to take the union of these tables.

CSC 240 (Blum)26 Union Example: Character and RealPerson names (DataSheet)

CSC 240 (Blum)27 Union Example: Character and RealPerson names (DataSheet)

CSC 240 (Blum)28 Union Example: Character and RealPerson names (No Design  ) Query-By-Example (QEB) which is what we do in Design View takes the join as its principle binary operation. While the union is a more fundamental binary operation in Relational algebra, the join is the more common operation in querying. SQL does have the union operation!

CSC 240 (Blum)29 Union Example: Character and RealPerson names

CSC 240 (Blum)30 Intersection The intersection of set A and set B contains only the elements that belong both to set A and to set B. Example: let us make a table containing all of the names of people who play themselves on the Simpsons.  FirstName,LastName (Character)   FirstName,LastName (RealPerson) Again the first step is to make union-compatible tables.

CSC 240 (Blum)31 Intersection Example: People playing themselves (DataSheet)

CSC 240 (Blum)32 Intersection Example: People playing themselves (Design, step 1)

CSC 240 (Blum)33 Intersection Example: People playing themselves (Design, step 2) Dragging a field icon from one table to another establishes a relationship. Right click on a line to remove a relationship from the query.

CSC 240 (Blum)34 Intersection Example: People playing themselves (SQL) SQL has an INTERSECT operation like its UNION operation, but it is not supported by Access.

CSC 240 (Blum)35 Intersection Example: People playing themselves (Design, version 2) concatenation Uses concatenation and a subquery. subquery

CSC 240 (Blum)36 Intersection Example: People playing themselves (SQL, version 2) Note: Access adds lots of parentheses.

CSC 240 (Blum)37 Set Difference The set difference of Set A and Set B is all of the elements in Set A that are not also elements of set B. Example: Simpsons characters who are not real people.  FirstName,LastName (Character) -  FirstName,LastName (RealPerson) Again the first step is to make union- compatible tables.

CSC 240 (Blum)38 Set Difference Example: Characters that are not real people (DataSheet) Ernest Borgnine and James Brown removed.

CSC 240 (Blum)39 Set Difference Example: Characters that are not real people (Design) Same as the second version of the Intersection query except IN  NOT IN

CSC 240 (Blum)40 Set Difference Example: Characters that are not real people (SQL)

CSC 240 (Blum)41 Cartesian Product A row in the Cartesian product of Table A and Table B is the concatenation of a row from Table A and a row from Table B. All possible combinations of a row from A and a row from B are made. A  B On its own the Cartesian product is not very useful, but it is the first ingredient in a join, which is very useful in querying relational databases.

CSC 240 (Blum)42 How big is the Cartesian product? ABC DEF GHI JKL Degree(A) Cardinality(A) AN GO DU DE JV Cardinality(B) Degree(B) Cardinality(A  B) = Cardinality(A) * Cardinality(B) Degree(A  B) = Degree(A) + Degree(B)

CSC 240 (Blum)43 ABCAN ABCGO ABCDU ABCDE ABCJV DEFAN DEFGO DEFDU DEFDE DEFJV GHIAN GHIGO GHIDU GHIDE GHIJV JKLAN JKLGO JKLDU JKLDE JKLJV

CSC 240 (Blum)44 Perform a Selection on the Cartesian Product Recall that –(Most of) our tables correspond to entities. –Entities have relationships. –Relationships are realized by having fields in two tables take values from the same domain. E.g. That a Character is voiced by a Real Person is represented by having the PersonID (which identifies a person in the RealPerson Table) appear the Character Table.

CSC 240 (Blum)45

CSC 240 (Blum)46 Perform a Selection on the Cartesian Product (Cont.) The Cartesian product of the Character and RealPerson Tables has rows in which the person voices the character and rows in which the person does not voice the character. What distinguishes the former is that the Character.PersonID matches the RealPerson.PersonID. We can use this condition (predicate) to select out the meaningful rows.

CSC 240 (Blum)47 ABCAN ABCGO ABCDU ABCDE ABCJV DEFAN DEFGO DEFDU DEFDE DEFJV GHIAN GHIGO GHIDU GHIDE GHIJV JKLAN JKLGO JKLDU JKLDE JKLJV match

CSC 240 (Blum)48 After the selection ABCAN DEFDU DEFDE GHIGO JKLJV Now we have a table with two identical columns. We can eliminate one (or both) by projecting.

CSC 240 (Blum)49 After projection ABCN DEFU DEFE GHIO JKLV The combination of Cartesian product, selection and projection allows you to bring together the related information that was placed in different tables. This is the key operation in querying. It is called a join.

CSC 240 (Blum)50 RealPerson Table

CSC 240 (Blum)51 Credential Table

CSC 240 (Blum)52 Cartesian Product of Character and Credential Tables (in Excel) The credentials belong to Groening.

CSC 240 (Blum)53 Question Do I throw out people even if I don’t have any credentials for them? There are different types of joins.

CSC 240 (Blum)54 References Database Systems, Rob and Coronel Database Systems, Connolly and Begg