Chapter 2: Intro to Relational Model

Similar documents
Chapter 2: Intro to Relational Model

Database Technology Introduction. Heiko Paulheim

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Chapter 2: Relational Model

CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model

Relational Algebra. Procedural language Six basic operators

Relational Model, Relational Algebra, and SQL

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi

Chapter 6: Formal Relational Query Languages

Chapter 2: Relational Model

Chapter 3: Relational Model

Chapter 1: Introduction

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation!

Chapter 2: Relational Model

Chapter 2 Introduction to Relational Models

CSCB20 Week 2. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU

Database System Concepts

CMP-3440 Database Systems

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

RELATIONAL DATA MODEL

2.2.2.Relational Database concept

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Relational Query Languages: Relational Algebra. Juliana Freire

RELATIONAL DATA MODEL: Relational Algebra

Chapter 6 Formal Relational Query Languages

Chapter 3: Introduction to SQL

Relational Algebra 1. Week 4

Chapter 3: Introduction to SQL

The Extended Algebra. Duplicate Elimination. Sorting. Example: Duplicate Elimination

Relational Algebra and SQL

Chapter 13: Query Optimization

Relational Database: The Relational Data Model; Operations on Database Relations

Chapter 4. The Relational Model

RELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

CS2300: File Structures and Introduction to Database Systems

Chapter 6 - Part II The Relational Algebra and Calculus

Unit 3 : Relational Database Design

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS

Midterm Review. Winter Lecture 13

Comp 5311 Database Management Systems. 2. Relational Model and Algebra

Fundamentals of Database Systems

CS 582 Database Management Systems II

Web Science & Technologies University of Koblenz Landau, Germany. Relational Data Model

Relational Databases

Chapter 6 Part I The Relational Algebra and Calculus

Relational Algebra and SQL. Basic Operations Algebra of Bags

Relational Algebra. ICOM 5016 Database Systems. Roadmap. R.A. Operators. Selection. Example: Selection. Relational Algebra. Fundamental Property

CS 377 Database Systems

Relational Algebra. Algebra of Bags

CS275 Intro to Databases

Chapter 13: Query Optimization. Chapter 13: Query Optimization

Relational Model. Nisa ul Hafidhoh

COMP 244 DATABASE CONCEPTS AND APPLICATIONS

Relational Query Languages

Relational Algebra. Lecture 4A Kathleen Durant Northeastern University

Relational algebra. Iztok Savnik, FAMNIT. IDB, Algebra

The Relational Model and Relational Algebra

CSCB20 Week 3. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Relational Model and Relational Algebra A Short Review Class Notes - CS582-01

Introduction to Data Management. Lecture #11 (Relational Algebra)

Relational Model and Relational Algebra. Rose-Hulman Institute of Technology Curt Clifton

Relational Model & Algebra. Announcements (Thu. Aug. 27) Relational data model. CPS 116 Introduction to Database Systems

Relational Query Languages. Preliminaries. Formal Relational Query Languages. Example Schema, with table contents. Relational Algebra

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Informationslogistik Unit 4: The Relational Algebra

Relational Model and Relational Algebra

Relational Algebra. [R&G] Chapter 4, Part A CS4320 1

CS 4400 Exam 2 ANSWER KEY

Relational Algebra Part I. CS 377: Database Systems

CSC 261/461 Database Systems Lecture 13. Fall 2017

1 Relational Data Model

Chapter 6 The Relational Algebra and Calculus

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Relational Algebra BASIC OPERATIONS DATABASE SYSTEMS AND CONCEPTS, CSCI 3030U, UOIT, COURSE INSTRUCTOR: JAREK SZLICHTA

Rela+onal Algebra. Rela+onal Query Languages. CISC437/637, Lecture #6 Ben Cartere?e

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

Relational Algebra and Calculus

What s a database system? Review of Basic Database Concepts. Entity-relationship (E/R) diagram. Two important questions. Physical data independence

RELATIONAL ALGEBRA. CS 564- Fall ACKs: Dan Suciu, Jignesh Patel, AnHai Doan

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects.

EECS 647: Introduction to Database Systems

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board

Relational Model. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

L22: The Relational Model (continued) CS3200 Database design (sp18 s2) 4/5/2018

Selection and Projection

CS425 Fall 2017 Boris Glavic Chapter 4: Introduction to SQL

Lecture 16. The Relational Model

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

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Databases 1. Daniel POP

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Algebra. Relational Query Languages

Chapter 3. The Relational Model. Database Systems p. 61/569

ECE 650 Systems Programming & Engineering. Spring 2018

Chapter 8: Relational Database Design

Transcription:

Non è possibile visualizzare l'immagine. Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use

Example of a Relation attributes (or columns) tuples (or rows) 2.2

Attribute Types The set of allowed values for each attribute is called the domain of the attribute Attribute values are (normally) required to be atomic; that is, indivisible The special value null is a member of every domain. Indicated that the value is unknown The null value causes complications in the definition of many operations 2.3

Relation Schema and Instance A 1, A 2,, A n are attributes R = (A 1, A 2,, A n ) is a relation schema Example: instructor = (ID, name, dept_name, salary) Formally, given sets D 1, D 2,. D n a relation r is a subset of D 1 x D 2 x x D n Thus, a relation is a set of n-tuples (a 1, a 2,, a n ) where each a i Î D i The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table 2.4

Relations are Unordered Order of tuples is irrelevant (tuples may be stored in an arbitrary order) Example: instructor relation with unordered tuples 2.5

Keys Let K Í R K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(r) Example: {ID} and {ID,name} are both superkeys of instructor. Superkey K is a candidate key if K is minimal Example: {ID} is a candidate key for Instructor One of the candidate keys is selected to be the primary key. which one? Foreign key constraint: Value in one relation must appear in another Referencing relation Referenced relation Example dept_name in instructor is a foreign key from instructor referencing department 2.6

Schema Diagram for University Database 2.7

Relational Query Languages Procedural vs.non-procedural, or declarative Pure languages: Relational algebra Tuple relational calculus Domain relational calculus The above 3 pure languages are equivalent in computing power We will concentrate in this chapter on relational algebra Not Turing-machine equivalent It consists of 6 basic operations 2.8

Select operation selection of rows (tuples) Relation r s A=B ^ D > 5 (r) 2.9

Project operation selection of columns (attributes) Relation r: ÕA,C (r) 2.10

Union of two relations Relations r, s: r È s: 2.11

Set difference of two relations Relations r, s: r s: 2.12

Set intersection of two relations Relation r, s: r Ç s Note: r Ç s = r (r s) 2.13

Joining two relations Cartesian product Relations r, s: r x s: 2.14

Cartesian product naming issue Relations r, s: B r.b r x s: s.b 2.15

Renaming a table Allows us to refer to a relation, (say E) by more than one name. r x (E) returns the expression E under the name X Relations r r x r s (r) r.a r.b s.a s.b α α β β 1 1 2 2 α β α β 1 2 1 2 2.16

Composition of operations Can build expressions using multiple operations Example: s A=C (r x s) r x s s A=C (r x s) 2.17

Joining two relations Natural Join Let r and s be relations on schemas R and S respectively. Then, the natural join of relations R and S is a relation on schema R È S obtained as follows: Consider each pair of tuples t r from r and t s from s. If t r and t s have the same value on each of the attributes in R Ç S, add a tuple t to the result, where 4 t has the same value as t r on r 4 t has the same value as t s on s 2.18

Natural Join Example Relations r, s: Natural Join r s Õ A, r.b, C, r.d, E (s r.b = s.b r.d = s.d (r x s))) 2.19

Notes about relational languages Each query input is a table (or a set of tables) Each query output is a table. All data in the output table appears in one of the input tables Relational Algebra is not Turing complete Can we compute: SUM AVG MAX MIN 2.20

Summary of Relational Algebra Operators Symbol (Name) σ (Selection) Π (Projection) x (Cartesian Product) (Union) - (Set Difference) (Natural Join) Example of Use σ salary > = 85000 (instructor) Return rows of the input relation that satisfy the predicate. Π ID, salary (instructor) Output specified attributes from all rows of the input relation. Remove duplicate tuples from the output. instructor x department Output pairs of rows from the two input relations that have the same value on all attributes that have the same name. Π name (instructor) Π name (student) Output the union of tuples from the two input relations. Π name (instructor) -- Π name (student) Output the set difference of tuples from the two input relations. instructor department Output pairs of rows from the two input relations that have the same value on all attributes that have the same name. 2.21

Non è possibile visualizzare l'immagine. End of Chapter 2 Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use