RELATIONAL ALGEBRA Prof. Sin-Min LEE Department of Computer Science.

Slides:



Advertisements
Similar presentations
Relational Algebra Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Advertisements

Chapter 3 : Relational Model
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
RELATIONAL ALGEBRA (II) Prof. Sin-Min LEE Department of Computer Science.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
FALL 2004CENG 351 File Structures and Data Managemnet1 Relational Algebra.
RELATIONAL ALGEBRA Prof. Sin-Min LEE Department of Computer Science.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
RELATIONAL ALGEBRA Prof. Sin-Min LEE Department of Computer Science.
1 Relational Algebra. 2 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
RELATIONAL ALGEBRA (III) Prof. Sin-Min LEE Department of Computer Science.
RELATIONAL ALGEBRA (II) Prof. Sin-Min LEE Department of Computer Science.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
RELATIONAL ALGEBRA Prof. Sin-Min LEE Department of Computer Science.
Rutgers University Relational Algebra 198:541 Rutgers University.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
RELATIONAL ALGEBRA (II) Prof. Sin-Min LEE Department of Computer Science.
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
Databases Illuminated
Relational Algebra.  Introduction  Relational Algebra Operations  Projection and Selection  Set Operations  Joins  Division  Tuple Relational Calculus.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
1 The Relational Model By Elena Ciriani CS157A February 19, 2004 Professor Lee.
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
Relational Algebra  Souhad M. Daraghma. Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
ICS 321 Fall 2011 The Relational Model of Data (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 8/29/20111Lipyeow.
The Relational Algebra and Calculus
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
CMPT 258 Database Systems Relational Algebra (Chapter 4)
Relational Algebra p BIT DBMS II.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
RELATIONAL ALGEBRA (II)
Module 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Relational Algebra.
LECTURE 3: Relational Algebra
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Chapter 2: Intro to 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
CENG 351 File Structures and Data Managemnet
Presentation transcript:

RELATIONAL ALGEBRA Prof. Sin-Min LEE Department of Computer Science

Terminology: ztable (relation) zrow (tuple) yformally, a relation is a set of ordered n- tuples. Domain : set of data values from which an attribute value can be drawn. Eg. yset of department names yset of legal salaries yset of possible employee birth dates

If D 1, D 2, D 3 ……. D n are the domains of a relation R. Then, R  D 1 x D 2 x D 3 x ………..x D n.

What are the query languages? zIt is an abstract language. We use it to express the set of operations that any relational query language must perform. zTwo types of operations: z 1.set-theoretic operations: tables are essentially sets of rows  2.native relational operations: focus on the structure of the rows Query languages are specialized languages for asking questions,or queries,that involve the data in database.

Database Scheme A relational database scheme, or schema, corresponds to a set of table definitions. Eg: product(p_id, name, category, description) supply(p_id, s_id, qnty_per_month) supplier(s_id, name, address, ph#) * remember the difference between a DB instance and a DB scheme.

Keys zThe super key, candidate key and primary key notations presented for ER model apply for relational model also.

Query languages zprocedural vs. non-procedural zcommercial languages have some of both zwe will study: yrelational algebra ( which is procedural, i.e. tells you how to process a query ) yrelational calculus ( which is non-procedural i.e. tells what you want )

Relational Algebra Fundamental operators  select   project  zcartesian product  zunion  zset difference - Other operators znatural join JOIN (butterfly symbol) zset intersection  zdivision 

A Simple DB account ac# owner ss# balance 1 bob sue jane transaction t# ac# type amount outcome date 1 1 W 1500 bounced 5/1/ D 1000 ok 5/2/ W 100 ok 5/4/ D 500 ok 5/7/ W 200 ok 5/9/98 account had transaction

Select eg:  balance>=1500 account result : ac# owner ss# balance 2 sue jane Project eg: π owner, ss# account result: owner ss# bob 123 sue 456 jane 789

Cartesian product eg: account  transaction ythis will have 15 rows like the ones shown below: ac# owner ss# balance t# type amount outcome date 1 bob W 1500 bounced 5/1/98 2 sue D 1000 ok 5/2/98 …………… Composing operations eg: “show all transactions done by account owner Bob”. σ account.ano= transaction.ano ((  owner=“Bob” account)  transaction)

zNatural Join - combines σ, π,  - very commonly used Natural Join forms the cross product of its two arguments, does a selection to enforce equality of columns with the same name and removes duplicate columns. Eg: “show all transactions done by account owner Bob” σ owner=“Bob” (account JOIN transaction)

Rename operation What if you need to access the same relation twice in a query? eg. person(ss#, name, mother_ss#, father_ss#) “Find the name of Bob’s mother” needs the “person” table to be accessed twice. The operation ρ x (r) evaluates to a second logical copy of relation r renamed to x.

Rename operation (contd) eg: π mother.name ( (ρ mother (person)) JOIN mother.ss# = person.mother_ss# (  name=“Bob ” (person)))

Additional Operations Additional Operations are those that can be expressed in terms of other operations. zSet Intersection r  s = r-(r-s) eg.: r a b s a b r  s = a b 1 a 1 a 1 a 2 b 2 c 3 d 3 d 3 d r s

Additional Operations(cntd.) zDivision  yuseful for “for all” queries Definition: Let r(R) and s(S), where R & S are sets of attributes, be relations, where S is a subset of R. The relation r  s has scheme R-S. The tuples in r  s consist of the R-S part of the tuples of r such that some tuple t r in r with the those R-S attribute values matches every tuple in s. zCan also be defined in terms of relational algebra.

Additional Operations(cntd.) zAssignment operation Sometimes it is convenient to write a relational algebra expression as a sequence of steps rather than one large expression. To do this, you can use assignment: relname expression eg.: temp π pno (part) bigsuppliers supply  temp