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

Similar documents
2.2.2.Relational Database concept

Relational Model, Relational Algebra, and SQL

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

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

CSC Discrete Math I, Spring Sets

Relational Algebra 1

What Is A Relation? Example. is a relation from A to B.

Slides for Faculty Oxford University Press All rights reserved.

Chapter 6 Part I The Relational Algebra and Calculus

1 Relational Data Model

Relational Algebra and SQL

Relational Algebra and SQL. Basic Operations Algebra of Bags

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

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

Relational Algebra. Relational Query Languages

EECS 647: Introduction to Database Systems

Relational Algebra. Algebra of Bags

Chapter 2: Intro to Relational Model

Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Sets Fall / 31

CS 377 Database Systems

CS 582 Database Management Systems II

Chapter 2: Intro to Relational Model

Chapter 6 The Relational Algebra and Calculus

Relational Query Languages: Relational Algebra. Juliana Freire

ECE 650 Systems Programming & Engineering. Spring 2018

A set with only one member is called a SINGLETON. A set with no members is called the EMPTY SET or 2 N

Relational Model 2: Relational Algebra

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

RELATIONAL DATA MODEL: Relational Algebra

A l Ain University Of Science and Technology

Relational Databases

12. Predicate Logic Structures. The Lecture

Discrete Mathematics Lecture 4. Harper Langston New York University

SQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure.

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

Relational Algebra for sets Introduction to relational algebra for bags

CMP-3440 Database Systems

2 Review of Set Theory

The Relational Algebra

Chapter 2 The relational Model of data. Relational algebra

Chapter 3: Introduction to SQL

9.5 Equivalence Relations


Relational Algebra. Mr. Prasad Sawant. MACS College. Mr.Prasad Sawant MACS College Pune

Chapter 3: Introduction to SQL

Relational Algebra. Lecture 4A Kathleen Durant Northeastern University

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

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

Ian Kenny. November 28, 2017

Chapter 6 The Relational Algebra and Relational Calculus

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

The SQL data-definition language (DDL) allows defining :

1 Finite Representations of Languages

COMP 244 DATABASE CONCEPTS AND APPLICATIONS

Database Management Systems Paper Solution

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

Review of Sets. Review. Philippe B. Laval. Current Semester. Kennesaw State University. Philippe B. Laval (KSU) Sets Current Semester 1 / 16

Relational Algebra. Procedural language Six basic operators

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

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

v Conceptual Design: ER model v Logical Design: ER to relational model v Querying and manipulating data

2.1 Sets 2.2 Set Operations

Unit- III (Functional dependencies and Normalization, Relational Data Model and Relational Algebra)

2.3 Algorithms Using Map-Reduce

CHAPTER 8. Copyright Cengage Learning. All rights reserved.

RELATION AND RELATIONAL OPERATIONS

Databases-1 Lecture-01. Introduction, Relational Algebra

Databases - Relational Algebra. (GF Royle, N Spadaccini ) Databases - Relational Algebra 1 / 24

Relational Model: History

This lecture. Projection. Relational Algebra. Suppose we have a relation

3. Relational Data Model 3.5 The Tuple Relational Calculus

Chapter 3: SQL. Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Chapter 5 Relational Algebra. Nguyen Thi Ai Thao

Relational terminology. Databases - Sets & Relations. Sets. Membership

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

Chapter 3: SQL. Chapter 3: SQL

Midterm Review. Winter Lecture 13

Information Systems. Relational Databases. Nikolaj Popov

10/11/2018. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings

Announcements. Relational Model & Algebra. Example. Relational data model. Example. Schema versus instance. Lecture notes

Relational Query Languages

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

Relational Model and Relational Algebra

Basic operators: selection, projection, cross product, union, difference,

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

6. Relational Algebra (Part II)

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

Finite State Machines: Motivating Examples

Relational Model & Algebra. Announcements (Tue. Sep. 3) Relational data model. CompSci 316 Introduction to Database Systems

Introduction to Sets and Logic (MATH 1190)

Chapter 4: SQL. Basic Structure

Database Systems. Basics of the Relational Data Model

Database Systems SQL SL03

1.1 - Introduction to Sets

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions

Relational Algebra Part I. CS 377: Database Systems

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

University of Helsinki / CS Introduction to Databases, spring 2004 Relational algebra Harri Laine 1. Relational algebra. Relational algebra

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

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

Transcription:

Relational Database: The Relational Data Model; Operations on Database Relations Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin

Overview Review of relations in mathematics Database relations Operations on database relations

Review of Relations in Mathematics Cross product Binary relation over a single set Generalization to n-ary relations

Cross Product Let A and B be two sets Then A B is the set consisting of all pairs (a, b) such that a A and b B For finite sets A and B, A B = A B

Binary Relation over a Set S Simply a subset of S S So there are 2 9 = 512 different relations that one can define over the set {1, 2, 3} Example: {(1, 2), (1, 3), (2, 3)} is a relation over {1, 2, 3} The preceding relation, call it R, happens to correspond to the operator < in the sense that (x, y) belongs to R if and only if x < y Various properties of such relations are commonly defined, such as reflexivity, symmetry, transitivity These concepts are not important in the context of database relations

Binary Relation A binary relation over a (ordered) pair of sets A and B is a subset of A B Example: If A = {1, 2, 3} and B = {2, 5} then any subset of {(1, 2), (1, 5), (2, 2), (2, 5), (3, 2), (3, 5)} is a relation over A and B

Generalization to k-ary Relations Suppose we are given a sequence of sets A 1,..., A k A k-ary relation with respect to this sequence is any subset of A 1 A k

Database Relations Consists of two parts: A relational schema A set of tuples

Relational Schema A set of attributes, each of which has an associated set called the domain of the attribute Example: One attribute of a relation that contains information about students might be birthdate The domain of this attribute is the set of all valid dates

The Set of Tuples of a Database Relation Each tuple specifies a value for each attribute of the relation

Table Representation of a Database Relation A database relation is often represented as a table There is one column for each attribute The order of the columns is unimportant, i.e., reordering the columns does not yield a different relation There is one row for each tuple The order of the rows is also unimportant The entry in row i and column j is the value assigned by the ith tuple to the jth attribute

Relational Database A relational database is a set of database relations with distinct names Typically, every database relation in a relational database D has a common attribute with some other database relation in D

Relational Algebra An algebra consists of elements, operations, and identities Example: Algebra of basic arithmetic over the integers Elements are the integers Operations are +,,, Identities are equations such as x + y = y + x, x (y + z) = x y + x z, where x, y, and z range over the elements (i.e., integers) In relational algebra, the elements are database relations We will now introduce a number of basic operations on database relations

Operations on Database Relations Union Intersection Difference Cross product (also called cartesian product) Projection Selection (Natural) Join

Operations on Compatible Database Relations Two database relations are said to be union-compatible, or simply compatible, if they have the same relational schema, i.e., the same set of attributes The union, intersection, and difference operations are only defined over compatible database relations R and S In each case, the resulting database relation is compatible with R and S The set of tuples of R S consists of those tuples in either R or S The set of tuples of R S consists of those tuples in both R and S The set of tuples of R S consists of those tuples in R but not S

Cross Product R S of Database Relations R and S First, assume that R and S have no common attributes In this case, the set of attributes of R S is the union of those of R and S The tuples of R S are all tuples that can be formed by concatenating a tuple in R with a tuple in S So the number of tuples in R S is equal to the number in R times the number in S What if R and S have common attributes? Rename the attributes to ensure that they are all distinct, and then proceed as above

Projection of a Database Relation R Specifies the subset of the attributes of R to be retained When we drop the other attributes, we may get duplicates Such duplicates are removed Thus the number of tuples in any projection of R is at most the number of tuples in R We write π u1,...,u k (R) to denote the projection of database relation R that retains attributes u 1,..., u k

Selection Selection from a database relation R involves specifying a predicate p defined over the tuples of R, i.e., p maps each tuple of R to a boolean value We write σ p (R) to denote the relation consisting of the subset of tuples of R that satisfy predicate p The relational schema of σ p (R) is the same as that of R

(Natural) Join The join of database relations R and S is denoted R S The join may be viewed as a more refined way of taking cross product As in the cross product, we consider each tuple r in R and s in S If r and s match in their common attributes, concatenate them keeping only one set of columns for the common attributes However, in the special case where R and S have no common attributes, we do not consider R S to be the same as R S Instead, R S is defined to be the empty relation with the same relational schema as R S