Relational Algebra II. Semantics - where A WHERE X  Y –  : an operator like =, >, … Result of restriction A by the condition X  Y is A relation –with.

Slides:



Advertisements
Similar presentations
Relational Database Operators
Advertisements

Relational Algebra and Relational Calculus
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 5A Relational Algebra.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Relational Algebra 1 Chapter 5.1 V3.0 Napier University Dr Gordon Russell.
Oct 28, 2003Murali Mani Relational Algebra B term 2004: lecture 10, 11.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
Domains, Relations & Base RelVars (Ch
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
RELATIONAL ALGEBRA (II) Prof. Sin-Min LEE Department of Computer Science.
Relational Algebra. Relational algebra Consists of collection of operators –Restrict, project, join, … Takes relations as operands Returns relations as.
1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational.
Nov 18, 2003Murali Mani Relational Algebra B term 2004: lecture 10, 11.
Murali Mani Relational Algebra. Murali Mani What is Relational Algebra? Defines operations (data retrieval) for relational model SQL’s DML (Data Manipulation.
RELATIONAL ALGEBRA Objectives
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Chapter 3 Section 3.4 Relational Database Operators
1 Session 3 Welcome: To session 3-the 8 th. learning sequence “Relational algebra “ Recap : In the previous learning sequence, we discussed some example.
The Relational Model Part III. Remember: 3 Aspects of the Model It concerns 1) data objects storing it 2) data integrity making sure it corresponds to.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
Logical Database Design ( 補 ) Unit 7 Logical Database Design ( 補 )
Relational Algebra - Chapter (7th ed )
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
SQL Part I: Standard Queries. COMP-421: Database Systems - SQL Queries I 2 Example Instances sid sname rating age 22 debby debby lilly.
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
Advanced Database Systems
Relational Algebra Relational Operators – Set operations –Special relational operators Relational Algebra Expressions PROJECT (SELECT FROM (A TIMES B)…
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
From Relational Algebra to SQL CS 157B Enrique Tang.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
Chapter 5 Relational Algebra Pearson Education © 2014.
1 Geog 357 – Introduction to GIS The Relational Language.
Relational Algebra Operators
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Advanced Relational Algebra & SQL (Part1 )
1 Algebra of Queries Classical Relational Algebra It is a collection of operations on relations. Each operation takes one or two relations as its operand(s)
Views, Algebra Temporary Tables. Definition of a view A view is a virtual table which does not physically hold data but instead acts like a window into.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
CMPT 258 Database Systems SQL Queries (Chapter 5).
SQL - miscellaneous D. Christozov / G.Tuparov INF 280 Database Systems: SQL – miscellaneous 1.
Relational Algebra Prof. Yin-Fu Huang CSIE, NYUST Chapter 7.
Dr. Mohamed Hegazi1 The Relational Algebra and Relational Calculus.
Views Prof. Yin-Fu Huang CSIE, NYUST Chapter 10. Advanced Database System Yin-Fu Huang 10.1Introduction Example: Var Good_Supplier View (S Where Status.
1.2 Linear Equations and Rational Equations. Terms Involving Equations 3x - 1 = 2 An equation consists of two algebraic expressions joined by an equal.
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
Structured Query Language IV Asma Ahmad (C. J. Date) Database Systems.
Ritu CHaturvedi Some figures are adapted from T. COnnolly
Relational Algebra Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
STRUCTURE OF PRESENTATION :
COMP3017 Advanced Databases
UNIT 11 Query Optimization
Chapter 8 Relational Calculus.
INSTALLMENT NUMBER 21 Relational Comparisons
The Relational Algebra and Relational Calculus
More Relational Algebra
Φροντιστήριο SQL (από το βιβλίο του Date)
Advanced Database System
Unit 7 Normalization (表格正規化).
The Relational Algebra
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
Unit Relational Algebra 1
Chapter 4 Relational Algebra
Presentation transcript:

Relational Algebra II

Semantics - where A WHERE X  Y –  : an operator like =, >, … Result of restriction A by the condition X  Y is A relation –with the same heading as A –With body consisting of all tuples t of A s.t. condition X  Y is true in the result The following expressions are equivalent A WHERE c1 AND c2  (A WHERE c1) INTERSECT (A WHERE c2) A WHERE c1 OR c2  (A WHERE c1) UNION (A WHERE c2) A WHERE NOT c  A MINUS (A WHERE c)

Semantics – where(cont.) Ex) S WHERE CITY = ‘ Paris ’ (original) (result) Ex) SP WHERE S# = S#( ‘ S7 ’ ) OR P# = P#( ‘ P7 ’ ) (result) S#SNAMESTATUSCITY S2Jones10Paris S3Brakes30Pairs S#P#QTY

Semantics - project A{X, …, Z} –Projection of relation with respect to attributes, X, …, Z –Duplicate tuples are eliminated Ex) S {CITY} Ex) {S WHERE CITY = ‘ London ’ }{S#} CITY London Paris Athenes S# S1 S4

Semantics - join In general, Join means natural join –All possible tuples that are combination of two relations such that two tuples contributing to any given combination have a common value for the common attributes Natural join needs common attributes between 2 relations Natural join is not primitive operation –A projection of a restriction of a product Ex) S JOIN P  ((S TIMES (P RENAME CITY AS PCITY)) WHERE CITY = PCITY) {ALL BUT PCITY}

Semantics -  -join Join on the basis of some comparison operator other than ‘ = ‘ –(A TIMES B) WHERE X  Y Ex) ((S RENAME CITY AS SCITY) TIMES (P RENAME CITY AS PCITY)) WHERE SCITY > PCITY S#SNAMESTATUSSCITYP#PNAM E COLO R WEIGHTPCITY S2Jones10ParisP1NutRed12.0London S2Jones10ParisP4ScrewRed14.0London S2Jones10ParisP6CogRed19.0London S3Blakes30ParisP1NutRed12.0London S3Blakes30ParisP4ScrewRed14.0London S3Blekes30ParisP6CogRed19.0London

Semantics - equijoin When  is =, the  -join is equijoin The result includes two attributes in which the values in the attributes are equal If one of the two attributes is eliminated, it is the natural join

Semantics – outer join Keep all tuples in one of the relations –Left outer join Keep all tuples in the left of the operator –Right outer join Keep all tuples in the right of the operator Ex) S LEFT OUTER JOIN P S P S#CITY S1 S2 S3 London Paris Athenes P#CITY P1 P2 London Paris S#P#CITY S1 S2 S3 P1 P2 null London Paris Athenes

Semantics - divide A DIVIDEBY B PER C –A relation with heading of A Body consisting of A ’ s tuples such that –They also exist in C as part –The part except A ’ s also is in B Ex) A B C S# S1 S2 S3 S4 S5 S#P# S1 S2 P1 P2 P3 P1 S# S1 P# P1 P2 P# P1 S# S1 S2

Semantics Associativity and Commutativity –UNION, INTERSECT, TIMES, JOIN, but not MINUS Ex) (A UNION B) UNION C  A UNION (B UNION C) A UNION B  B UNION A

Examples Get supplier names for suppliers who supply part P2 –Supplier name  S –Who supply what  SP –So, Join operation is needed –((SP JOIN S) WHERE P# = P#( ‘ P2 ’ )){SNAME}

Examples (cont.) Get supplier names for suppliers who supply at least one red part –Red part  P –P WHERE COLOR=COLOR( ‘ Red ’ ) –Additional condition: ‘ supply ’ and ‘ supplier name ’  join S and SP operation to the above result is needed (((P WHERE COLOR=COLOR( ‘ Red ’ )){P#} JOIN SP) JOIN S){SNAME}

Example (cont.2) Get supplier names for suppliers who supply all parts –Part supply  SP –All parts  P –Suppliers  S So, S {S#} DIVIDEDBY P {P#} PER SP {S#, P#}  supplier number So, join it with S –(( S {S#} DIVIDEDBY P {P#} PER SP {S#, P#}) JOIN S ) {SNAME}

Example Get supplier names for suppliers who supply all parts: S {S#} DIVIDEDBY P {P#} PER SP {S#, P#} Ex) S{S#} P{P#} SP{S#,P#} S# S1 S2 S3 S4 S5 S#P# S1 … P1 P2 P3 P4 P5 P6 … S# S1 P# P1 P2 P3 P4 P5 P6