Relational Calculus: 1

Similar documents
Chapter 6 - Part II The Relational Algebra and Calculus

CSC 742 Database Management Systems

DATABASE DESIGN II - 1DL400

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

Some different database system architectures. (a) Shared nothing architecture.

Chapter 5 Relational Algebra. Nguyen Thi Ai Thao

Chapter 8: The Relational Algebra and The Relational Calculus

Part 1 on Table Function

Relational Algebra & Calculus. CS 377: Database Systems

Chapter 6 5/2/2008. Chapter Outline. Database State for COMPANY. The Relational Algebra and Calculus

Database design process

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and

CIS611 Lab Assignment 1 SS Chung

The Relational Algebra and Calculus. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Announcement5 SQL5. Create%and%drop%table5. Basic%SFW%query5. Reading%a%table5. TDDD37%% Database%technology% SQL5

Session Active Databases (2+3 of 3)

Overview Relational data model

L130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries.

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries

Database Technology. Topic 3: SQL. Olaf Hartig.

ECE 650 Systems Programming & Engineering. Spring 2018

CIS 611. Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6-1

Advanced Databases. Winter Term 2012/13. Prof. Dr. Dietmar Seipel University of Würzburg. Advanced Databases Winter Term 2012/13

Relational Algebra Part I. CS 377: Database Systems

CS 348 Introduction to Database Management Assignment 2

SQL-99: Schema Definition, Basic Constraints, and Queries. Create, drop, alter Features Added in SQL2 and SQL-99

ECE 650 Systems Programming & Engineering. Spring 2018

SQL STRUCTURED QUERY LANGUAGE

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

Chapter 3. Algorithms for Query Processing and Optimization

Query 2: Pnumber Dnum Lname Address Bdate 10 4 Wallace 291 Berry, Bellaire, TX Wallace 291 Berry, Bellaire, TX

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints

Relational Algebra 1

UNIT 2 RELATIONAL MODEL

Dr. Anis Koubaa. Advanced Databases SE487. Prince Sultan University

Operations of Relational Algebra

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)

Database Technology. Topic 2: Relational Databases and SQL. Olaf Hartig.

UNIVERSITY OF TORONTO MIDTERM TEST SUMMER 2017 CSC343H Introduction to Databases Instructor Tamanna Chhabra Duration 120 min No aids allowed

Course Notes on Relational Algebra

Chapter 6 The Relational Algebra and Calculus

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

More SQL: Complex Queries, Triggers, Views, and Schema Modification

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

A taxonomy of SQL queries Learning Plan

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

SQL Introduction. CS 377: Database Systems

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

Relational Model. CS 377: Database Systems

CSIE30600/CSIEB0290 Database Systems Relational Algebra and Calculus 2

Integrity Coded Relational Databases (ICRDB) - Protecting Data Integrity in Clouds

Outline. CSIE30600 Database Systems Relational Algebra and Calculus 2

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences

Chapter 18 Strategies for Query Processing. We focus this discussion w.r.t RDBMS, however, they are applicable to OODBS.

CS5300 Database Systems

Querying a Relational Database COMPANY database For Lab4, you use the Company database that you built in Lab2 and used for Lab3

Relational Algebra. Relational Algebra Overview. Relational Algebra Overview. Unary Relational Operations 8/19/2014. Relational Algebra Overview

Chapter 8. Joined Relations. Joined Relations. SQL-99: Schema Definition, Basic Constraints, and Queries

Slides by: Ms. Shree Jaswal

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

RELATIONAL DATA MODEL

Views. Lecture 15. Robb T. Koether. Fri, Feb 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) Views Fri, Feb 16, / 28

DEPARTMENT DNAME DNUMBER MGRNAME MGRSTARTDATE

Chapter 19 Query Optimization

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Slide 25-1

Chapter 8: Relational Algebra

Relational Databases

Insertions, Deletions, and Updates

In Chapters 3 through 6, we presented various aspects

COSC Assignment 2

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

More SQL: Complex Queries, Triggers, Views, and Schema Modification

SQL: Advanced Queries, Assertions, Triggers, and Views. Copyright 2012 Ramez Elmasri and Shamkant B. Navathe

Selections. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 22, 2014

Views. Lecture 15 Section 5.3. Robb T. Koether. Hampden-Sydney College. Mon, Feb 18, 2013

Views. Lecture 15 Section 5.3. Robb T. Koether. Hampden-Sydney College. Mon, Feb 18, 2013

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

Database Systems External Sorting and Query Optimization. A.R. Hurson 323 CS Building

What happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques

COSC344 Database Theory and Applications. COSC344 Lecture 15 1

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

Chapter 6 Part I The Relational Algebra and Calculus

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

CSIE30600 Database Systems Basic SQL 2. Outline

The Relational Algebra

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

DBMS LAB SESSION PAVANKUMAR MP

SQL- Updates, Asser0ons and Views

More SQL: Complex Queries, Triggers, Views, and Schema Modification

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

DATABASE CONCEPTS. Dr. Awad Khalil Computer Science & Engineering Department AUC

Query formalisms for relational model relational calculus

Mobile and Heterogeneous databases Distributed Database System Query Processing. A.R. Hurson Computer Science Missouri Science & Technology

Relational Algebra. Ron McFadyen ACS

Simple SQL Queries (contd.)

The Relational Data Model and Relational Database Constraints

Transcription:

CSC 742 Database Management Systems Topic #8: Relational Calculus Spring 2002 CSC 742: DBMS by Dr. Peng Ning 1 Relational Calculus: 1 Can define the information to be retrieved not any specific series of operations In contrast, relation algebra defines the sequence of operations. Closer than relational algebra to how users would formulate queries in terms of their information needs, rather than in terms of operations. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 2 1

Relational Calculus: 2 Involves variables that range over tuples or domain attributes Tuple Relational Calculus: Variables range over tuples Domain Relational Calculus: Variables range over domain attributes Gives a way of referring to attributes of relations (and the specific tuples in them) Is based on predicate logic gives the usual quantifiers to construct complex queries. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 3 Tuple Relational Calculus (TRC) TRC is based on tuple variables. Each tuple variable ranges over a relation. The relation is called the range relation of the variable. Examples: {t Employee(t) and t.salary > 50000} Retrieve all attribute values. {t.fname, t.lname Employee(t) and t.salary > 50000} Retrieve selected attributes. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 4 2

Employee SSN Lname Fname Salary 111-22-3333 Smith John 30000 121-23-3333 Wong Frank 45000 153-32-1342 Wallace Jennifer 43000 154-33-3333 Borg James 56000 555-44-5555 English Joyce 53000 {t Employee(t) and t.salary > 50000} {t.fname, t.lname Employee(t) and t.salary > 50000} Spring 2002 CSC 742: DBMS by Dr. Peng Ning 5 TRC (Cont d) To specify a TRC expression: Specify the range relation R of each tuple variable t. In the form of R(t). Specify a condition to select particular combinations of tuples. Specify a set of attributes to be retrieved. {t.fname, t.lname Employee(t) and t.salary > 50000} Spring 2002 CSC 742: DBMS by Dr. Peng Ning 6 3

Employee SSN 111-22-3333 Lname Smith Fname John Salary 30000 121-23-3333 Wong Frank 45000 153-32-1342 Wallace Jennifer 43000 154-33-3333 Borg James 56000 555-44-5555 English Joyce 53000 1. Retrieve the salary of John Smith. 2. Retrieve the names of the employees whose salary is less than 40000. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 7 General TRC expression {t1.a,..., tn.an COND(t1,..., t(n+m))} COND COND & COND COND \/ COND ~COND ATOM ( t: COND) ( t: COND) Forms of ATOMs R(t) Ti.A op Tj.B, where op {=, >,, <,, }. Ti.A op c, where op {=, >,, <,, } and c is a constant. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 8 4

Tuple Variables Tuple variables in a COND may be bound: within the scope of a quantifier free: not within the scope of a quantifier Intuitively, the COND describes a property of its free variables All and only the free variables of COND can show up in the answer tuple as specified in TRC Spring 2002 CSC 742: DBMS by Dr. Peng Ning 9 {t.fname, t.lname Employee(t) and t.salary > 50000} {t.fname, t.lname Employee(t) and t.salary > 50000 and Department(d) and d.mgrssn = t.ssn} {t.fname, t.lname Employee(t) and t.salary > 50000 and ( d)(department(d) and d.mgrssn = t.ssn)} Spring 2002 CSC 742: DBMS by Dr. Peng Ning 10 5

Conventions Nested forall expressions can be simplified: ( t1: ( t2: C)) = ( t1, t2: C) Nested exists expressions can be simplified: ( t1: ( t2: C)) = ( t1, t2: C) For safety (described below), all tuple variables are declared to belong to some relation, e.g., project(p1) or employee(e2) Spring 2002 CSC 742: DBMS by Dr. Peng Ning 11 TRC Examples: 1 Find names of employees in the research dept Employee(Fname, Lname, SSN, Bdate, Address, Sex, Salary, SuperSSN, Dno) Department(Dname, Dnumber, MgrSSN, MgrStartDate) Spring 2002 CSC 742: DBMS by Dr. Peng Ning 12 6

TRC Examples: 2 For every project in 'Stafford' list the controlling dept number and the dept manager's last name Employee(Fname, Lname, SSN, Bdate, Address, Sex, Salary, SuperSSN, Dno) Department(Dname, Dnumber, MgrSSN, MgrStartDate) Project(Pname, Pnumber, Plocation, Dnum) Spring 2002 CSC 742: DBMS by Dr. Peng Ning 13 TRC Examples: 3 Find SSNs of employees who work on all the projects controlled by dept 5. Employee(Fname, Lname, SSN, Bdate, Address, Sex, Salary, SuperSSN, Dno) Works_on(ESSN, Pno, Hours) Project(Pname, Pnumber, Plocation, Dnum) Spring 2002 CSC 742: DBMS by Dr. Peng Ning 14 7

Using ER Diagrams ER diagrams can be used to understand and formulate queries Paths correspond to constraints on what is being retrieved can be mapped to calculus expressions encapsulate some common English grammatical constructions Spring 2002 CSC 742: DBMS by Dr. Peng Ning 15 Employee Works_on Project Find SSNs of employees who work on all the projects controlled by dept 5. Employee(Fname, Lname, SSN, Bdate, Address, Sex, Salary, SuperSSN, Dno) Works_on(ESSN, Pno, Hours) Project(Pname, Pnumber, Plocation, Dnum) Spring 2002 CSC 742: DBMS by Dr. Peng Ning 16 8

Safe TRC Expressions A Safe TRC expression: One that is guaranteed to yield a finite number of tuples as its result. An unsafe TRC expression {t not (Employee (t))} Spring 2002 CSC 742: DBMS by Dr. Peng Ning 17 Safe TRC Expressions (Cont d) Domain of a TRC expression: set of all values that appear in the expression or in any tuple of any relation mentioned in the expression Example: {t not (Employee (t))} Safe expressions: those whose result includes values only from their own domain {t Employee(t) &...} is safe because the answer is a subset of the Employee relation {t not (Employee (t))} is not safe because Spring 2002 CSC 742: DBMS by Dr. Peng Ning 18 9

Safe TRC Expressions (Cont d) Outer-level negations are unsafe Interestingly, even disjunctions can lead to trouble: {<x, y> R(x) \/ S(y)} returns tuples whose first member is in relation R or whose second member is in relation S. Suppose x1 is in R. Then the result contains <x1, y> for every y, irrespective of whether y is in S. Hence this query is not safe. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 19 Safe TRC Expressions (Cont d) Unsafe expressions are undesirable because they can involve infinite answer sets answers using values that the user (who produced the query) may have no way of predicting. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 20 10

Limitations of TRC It cannot express queries involving aggregations closure It cannot express non-query operations insert delete update because those involve modeling the changes in the state of a database. Spring 2002 CSC 742: DBMS by Dr. Peng Ning 21 11