1 Geog 357 – Introduction to GIS The Relational Language.

Slides:



Advertisements
Similar presentations
Relational Algebra and Relational Calculus
Advertisements

RELATIONAL DATABASES. Relational data Structure RELATION: Table with columns and rows ATTRIBUTE: Column of a relation DOMAIN: Set of allowable values.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
CSC271 Database Systems Lecture # 13. Summary: Previous Lecture  Grouping through GROUP BY clause  Restricted groupings  Subqueries  Multi-Table queries.
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.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
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 - Basic Operations CS263 Lecture 11.
1 Minggu 4, Pertemuan 8 SQL: Data Manipulation (Cont.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Relational Algebra. 2 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
1 Minggu 3, Pertemuan 5 Relational Algebra (Cont.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
Relational Algebra. Relational Query Languages n Query = “retrieval program” n Language examples: ù Theoretical : 1. Relational Algebra 2. Relational.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Chapter 6 SQL: Data Manipulation Cont’d. 2 ANY and ALL u ANY and ALL used with subqueries that produce single column of numbers u ALL –Condition only.
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.
1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational.
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
Relational Algebra.
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
Introduction to SQL Basics; Christoph F. Eick & R. Ramakrishnan and J. Gehrke 1 Introduction to SQL Basics --- SQL in 45 Minutes Chapter 5.
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.
Agenda TMA01 M876 Block 3 – Using SQL Structured Query Language - SQL A non-procedural language to –Create database and relation structures. –Perform.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L6_SQL(1) 1 SQL: Queries, Constraints, Triggers Chapter 5 – Part 1.
GUS: 0262 Fundamentals of GIS Lecture Presentation 3: Relational Data Model Jeremy Mennis Department of Geography and Urban Studies Temple University.
Relational Algebra Chapter 4 CIS 458 Sungchul Hong.
Chapter 6 SQL: Data Manipulation (Advanced Commands) Pearson Education © 2009.
ICS 321 Fall 2009 SQL: Queries, Constraints, Triggers Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/8/20091Lipyeow.
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
Advanced Database Systems
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.
CS 4432query processing1 CS4432: Database Systems II Lecture #11 Professor Elke A. Rundensteiner.
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.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
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.
IST 210 SQL Todd Bacastow IST 210: Organization of Data.
Chapter 5 Relational Algebra Pearson Education © 2014.
Advanced Relational Algebra & SQL (Part1 )
CSC271 Database Systems Lecture # 8. Summary: Previous Lecture  Relation algebra and operations  Selection (Restriction), projection  Union, set difference,
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
CMPT 258 Database Systems Relational Algebra (Chapter 4)
CMPT 258 Database Systems SQL Queries (Chapter 5).
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
Relational Algebra p BIT DBMS II.
IST 210 More SQL Todd Bacastow IST 210: Organization of Data.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
LECTURE THREE RELATIONAL ALGEBRA 11. Objectives  Meaning of the term relational completeness.  How to form queries in relational algebra. 22Relational.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples.
Ritu CHaturvedi Some figures are adapted from T. COnnolly
COMP3017 Advanced Databases
Relational Algebra and Relational Calculus
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
LECTURE 3: Relational Algebra
Chapter Name SQL: Data Manipulation
The Relational Algebra
Presentation transcript:

1 Geog 357 – Introduction to GIS The Relational Language

2 Relational data model Operations on the relational data model: defined by relational algebra  intersection  union  difference  join  projection  selection Each operation takes one or more tables as input and returns one table as output

3 Relational data model Intersection: find records common to two tables given certain criteria (an and operation)

4 Intersection: Find all classes that are Geography classes and that are also Gen Ed classes Geog357 Jones Geog115 Brower Geog20 Fountain Geog435 Karnes Geog20 Fountain Geog115 Brower Meteo110 Stankle Meteo200 Turlock Class Instructor Geography ClassesGen Ed Classes Geog20 Fountain Geog115 Brower Class Instructor Result of Intersection Relational data model

5 Union: find records common to either of two tables (an or operation)

6 Union: Find all classes that are either Geography classes or that are Gen Ed classes Geog357 Jones Geog115 Brower Geog20 Fountain Geog435 Karnes Geog20 Fountain Geog115 Brower Meteo110 Stankle Meteo200 Turlock Class Instructor Geography ClassesGen Ed Classes Geog357 Jones Geog20 Fountain Geog115 Brower Geog435 Karnes Meteo110 Stankle Meteo200 Turlock Class Instructor Relational data model Results of Union

7 Relational data model Difference: Find the records in one table that are not also present in another table (an xor operation)

8 Difference: Find all classes that are Geography classes but that are not Gen Ed classes Geog357 Jones Geog115 Brower Geog20 Fountain Geog435 Karnes Geog20 Fountain Geog115 Brower Meteo110 Stankle Meteo200 Turlock Class Instructor Geography ClassesGen Ed Classes Geog357 Jones Geog435 Karnes Class Instructor Relational data model Results of Difference

9 Relational data model Join: Match records in both tables based on a common field Geog357 Jones Geog115 Brower Geog20 Fountain Geog435 Karnes Class Instructor Geography Classes Jones 332 Brower 423 Fountain 125 Karnes 312 Instructor Office Instructor Geog357 Jones 332 Geog115 Brower 423 Geog20 Fountain 125 Geog435 Karnes 312 Class Instructor Office Result of Join

10 Relational data model Projection: reduces one table in the attribute dimension (a selection of a subset of fields, for all records)

11 Projection: List all Geography classes, but not the instructors Geog357 Jones Geog115 Brower Geog20 Fountain Geog435 Karnes Class Instructor Geography Classes Relational data model Geog357 Geog115 Geog20 Geog435 Class Result of Projection

12 Relational data model Selection (restriction): reduces one table in the record dimension (a selection of a subset of records, for all fields) Criteria for selection is called a predicate

13 Selection: Find Geography classes taught by ‘Jones’ Geog357 Jones Geog115 Brower Geog20 Fountain Geog435 Karnes Class Instructor Geography Classes Relational data model Result of Selection Geog357 Jones Class Instructor

14 Basic SQL Query relation-list A list of relation names (possibly with a range-variable after each name). target-list A list of attributes of relations in relation-list qualification Comparisons (Attr op const or Attr1 op Attr2, where op is one of ) combined using AND, OR and NOT. DISTINCT is an optional keyword indicating that the answer should not contain duplicates. Default is that duplicates are not eliminated! SELECT [DISTINCT] target-list FROM relation-list WHERE qualification

15 Selection Selects a subset of rows that satisfy a selection condition. Example: List all staff with a salary greater than $10,000 In SQL: SELECT * FROM Staff WHERE Salary > 10000

16 Projection Deletes attributes that are not in projection list. Schema of result contains exactly the fields in the projection list, with the same names that they had in the (only) input relation. Example: Produce a list of salaries for all staff, showing only the Sno, FName, LName, and Salary details. SQL SELECT sno, fname, Lname, Salary FROM Staff

17 Projection (cont…) In relational algebra, projection operator has to eliminate duplicates ! However, real SQL implementations typically don’t do duplicate elimination unless the user explicitly asks for it SELECT DISTINCT sno, fname, Lname, Salary FROM Staff

18 Cartesian Product R1 X R2 Allows us “to glue together” all possible combinations Each row of R1 is paired with each row of R2. Result schema has one field per field of R1 and R2, with field names inherited if possible.  Conflict : Both R1 and R2 could have a field called the same name. In SQL: SELECT FROM R1, R2

19 Example of Cartesian Product R1 R2 R1 X R2 R1. R2.

20 Union (R  S) R and S must be union-compatible They must have the same set of attributes with matching domains Union of two relations R and S with m and n tuples, respectively, is obtained by concatenating them into one relation with a maximum of ( m + n ) tuples, duplicate tuples being eliminated. Example: Construct a list of all areas where there is either a branch or a property. In SQL SELECT area FROM Branch UNION SELECT area FROM Property_for_Rent

21 Set Difference (R – S) Defines a relation consisting of the rows that are in relation R, but not in S. R and S must be union-compatible. Example: Construct a list of all cities where there is a branch office but no properties. In SQL: SELECT city FROM Brach EXCEPT SELECT city FROM Property_for_Rent

22 Join Operations A combination of Selection and Cartesian product operations SELECT FROM R, S WHERE {condition} There are various forms of join operation  Equi-join: {condition} contains only equality  Natural join: Equi-join on all common fields  Outer join: Retains rows that do not satisfy condition

23 Equi-join Example: List the names and comments of all renters who have viewed a property. SELECT Renter.rno, fname, lname, Viewing.rno, pno, comment FROM Renter, Viewing WHERE Renter.rno = Viewing.rno Reln 1Reln 2 Reln 1Reln 2

24 46 Natural Join Equi-join over all common attributes x. One occurrence of the common attribute is eliminated from the result. Example: List the names and comments of all renters who have viewed a property. SELECT rno, fname, lname, pno, comment FROM Renter, Viewing WHERE Renter.rno = Viewing.rno

25 Left Outer Join Result will include all tuples in the left relation even no match on join attribute Example: Produce a status report on property viewings. In SQL: SELECT pno, street, city, rno, date, comment FROM Property_for_Rent NATURAL LEFT OUTER JOIN Viewing