Relational Algebra at a Glance

Slides:



Advertisements
Similar presentations
1 Lecture 02: SQL. 2 Outline Data in SQL Simple Queries in SQL (6.1) Queries with more than one relation (6.2) Recomeded reading: Chapter 3, Simple Queries.
Advertisements

SQL Introduction Standard language for querying and manipulating data Structured Query Language Many standards out there: SQL92, SQL2, SQL3. Vendors support.
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Algebra Fall 2014.
Lecture 07: Relational Algebra
1 Relational Algebra. Motivation Write a Java program Translate it into a program in assembly language Execute the assembly language program As a rough.
Relational Algebra Dashiell Fryer. What is Relational Algebra? Relational algebra is a procedural query language. Relational algebra is a procedural query.
Relational Algebra (end) SQL April 19 th, Complex Queries Product ( pid, name, price, category, maker-cid) Purchase (buyer-ssn, seller-ssn, store,
Relational Algebra Maybe -- SQL. Confused by Normal Forms ? 3NF BCNF 4NF If a database doesn’t violate 4NF (BCNF) then it doesn’t violate BCNF (3NF) !
1 Lecture 12: SQL Friday, October 26, Outline Simple Queries in SQL (5.1) Queries with more than one relation (5.2) Subqueries (5.3) Duplicates.
Lecture #3 Functional Dependencies Normalization Relational Algebra Thursday, October 12, 2000.
1 Lecture 07: Relational Algebra. 2 Outline Relational Algebra (Section 6.1)
1 Lecture 3: More SQL Friday, January 9, Agenda Homework #1 on the web site today. Sign up for the mailing list! Next Friday: –In class ‘activity’
1 Information Systems Chapter 6 Database Queries.
Complex Queries (1) Product ( pname, price, category, maker)
Relational Schema Design (end) Relational Algebra Finally, querying the database!
One More Normal Form Consider the dependencies: Product Company Company, State Product Is it in BCNF?
Relation Decomposition A, A, … A 12n Given a relation R with attributes Create two relations R1 and R2 with attributes B, B, … B 12m C, C, … C 12l Such.
Integrity Constraints An important functionality of a DBMS is to enable the specification of integrity constraints and to enforce them. Knowledge of integrity.
Exercises Product ( pname, price, category, maker) Purchase (buyer, seller, store, product) Company (cname, stock price, country) Person( per-name, phone.
1. Midterm summary Types of data on the web: unstructured, semi- structured, structured Scale and uncertainty are key features Main goals are to model,
Lecture 3: Relational Algebra and SQL Tuesday, March 25, 2008.
Today Collection of unrelated stuff Questions? HW –4 -5 & drop lowest –emphasize project Projects Functional Dependencies? –Someone asked why: Keys, Normal.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
From Relational Algebra to SQL CS 157B Enrique Tang.
Datalog –Another query language –cleaner – closer to a “logic” notation, prolog – more convenient for analysis – can express queries that are not expressible.
1 Lecture 7: Normal Forms, Relational Algebra Monday, 10/15/2001.
Relational Algebra 2. Relational Algebra Formalism for creating new relations from existing ones Its place in the big picture: Declartive query language.
Advanced Relational Algebra & SQL (Part1 )
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
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.
CSE 326: Data Structures Lecture #22 Databases and Sorting Alon Halevy Spring Quarter 2001.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
Ritu CHaturvedi Some figures are adapted from T. COnnolly
Summary of Relational Algebra
Relational Algebra.
COMP3017 Advanced Databases
COP4710 Database Systems Relational Algebra.
Chapter # 6 The Relational Algebra and Calculus
Lecture 8: Relational Algebra
SQL Introduction Standard language for querying and manipulating data
06a: SQL-1 The Basics– Select-From-Where
Chapter 2: Intro to Relational Model
Lecture 2 (cont’d) & Lecture 3: Advanced SQL – Part I
Lecture 10: Relational Algebra (continued), Datalog
LECTURE 3: Relational Algebra
The Relational Algebra and Relational Calculus
Building a Database Application
SQL Introduction Standard language for querying and manipulating data
Lecture 9: Relational Algebra (continued), Datalog
Lecture 33: The Relational Model 2
Where are we? Until now: Modeling databases (ODL, E/R): all about the schema Now: Manipulating the data: queries, updates, SQL Then: looking inside -
Lecture 4: SQL Thursday, January 11, 2001.
Why use a DBMS in your website?
Chapter 2: Intro to Relational Model
Integrity Constraints
Relational Algebra Friday, 11/14/2003.
Lecture 3 Monday, April 8, 2002.
CS639: Data Management for Data Science
Chapter 2: Intro to Relational Model
Terminology Product Attribute names Name Price Category Manufacturer
Lecture 3: Relational Algebra and SQL
Relational Schema Design (end) Relational Algebra SQL (maybe)
Syllabus Introduction Website Management Systems
Lecture 11: Functional Dependencies
Presentation transcript:

Relational Algebra at a Glance Operators: sets as input, new set as output Basic Set Operators union, intersection, difference, but no complement. Selection: s Projection: p Cartesian Product: X Joins (natural,equi-join, theta join, semi-join) Renaming: r

Set Operations Binary operations Result is table(set) with same attributes Watch out for naming of attributes in resulting relation. Union: all tuples in R1 or R2 Intersection: all tuples in R1 and R2 Difference: all tuples in R1 and not in R2 No complement. Why? Bags later.

Selection Produce a subset of the tuples in a relation which satisfy a given condition Unary operation… returns set with same attributes, but ‘selects’ rows Use and, or, not, >, <… to build condition Find all employees with salary more than $40,000:

Find all employees with salary more than $40,000.

Projection Unary operation, selects columns Eliminates duplicate tuples Example: project social-security number and names.

Cartesian Product Binary Operation Result is tuples combining any element of R1 with any element of R2, for R1 X R2 Schema is union of Schema(R1) & Schema(R2)

Join (Natural) Most important, expensive and exciting. Combines two relations, selecting only related tuples Equivalent to a cross product followed by selection Resulting schema has all attributes of the two relations, but one copy of join condition attributes

Other Joins and Renaming Theta join: the join involves a predicate R S Semi-join: the attributes of one relation are included in the other. Renaming:

Complex Queries Product ( pname, price, category, maker) Purchase (buyer, seller, store, product) Company (cname, stock price, country) Person( per-name, phone number, city) Find phone numbers of people who bought gizmos from Fred. Find telephony products that somebody bought

Exercises Product ( pname, price, category, maker) Purchase (buyer, seller, store, product) Company (cname, stock price, country) Person( per-name, phone number, city) Ex #1: Find people who bought telephony products. Ex #2: Find names of people who bought American products Ex #3: Find names of people who bought American products and did not buy French products Ex #4: Find names of people who bought American products and they live in Seattle. Ex #5: Find people who bought stuff from Joe or bought products from a company whose stock prices is more than $50.

Operations on Bags (and why we care) Basic operations: Projection Selection Union Intersection Set difference Cartesian product Join (natural join, theta join)