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

Similar documents
Relational Model, Relational Algebra, and SQL

Relational Algebra and SQL

Database Systems. Basics of the Relational Data Model

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

Final Review. Zaki Malik November 20, 2008

FUNCTIONAL DEPENDENCIES

Normalization. Murali Mani. What and Why Normalization? To remove potential redundancy in design

Database Management Systems Paper Solution

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

Chapter 2: Intro to Relational Model

E-R diagrams and database schemas. Functional dependencies. Definition (tuple, attribute, value). A tuple has the form

Chapter 2: Intro to Relational Model

Relational Database Design Theory. Introduction to Databases CompSci 316 Fall 2017

Exam II Computer Programming 420 Dr. St. John Lehman College City University of New York 20 November 2001

Lecture 6a Design Theory and Normalization 2/2

Databases The theory of relational database design Lectures for m

Fundamentals of Database Systems

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS

Concepts from

CS411 Database Systems. 05: Relational Schema Design Ch , except and

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

Databases 1. Daniel POP

This lecture. Databases -Normalization I. Repeating Data. Redundancy. This lecture introduces normal forms, decomposition and normalization.

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2009 Lecture 4 - Schema Normalization

MODULE: 3 FUNCTIONAL DEPENDENCIES

Functional Dependencies and Finding a Minimal Cover

Ian Kenny. November 28, 2017

Database Design Principles

Functional Dependencies CS 1270

Unit 3 : Relational Database Design

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2009 Lecture 3 - Schema Normalization

2.2.2.Relational Database concept

Chapter 8: Relational Database Design

UNIT 3 DATABASE DESIGN

Schema Refinement: Dependencies and Normal Forms

Normalization. Anomalies Functional Dependencies Closures Key Computation Projecting Relations BCNF Reconstructing Information Other Normal Forms

Relational Design: Characteristics of Well-designed DB

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

Relational Model 2: Relational Algebra

Functional Dependencies & Normalization for Relational DBs. Truong Tuan Anh CSE-HCMUT

Steps in normalisation. Steps in normalisation 7/15/2014

Database Design Theory and Normalization. CS 377: Database Systems

Theory of Normal Forms Decomposition of Relations. Overview

Homework 6: FDs, NFs and XML (due April 13 th, 2016, 4:00pm, hard-copy in-class please)

Chapter 7: Relational Database Design

Relational Query Languages: Relational Algebra. Juliana Freire

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Normalisation. Normalisation. Normalisation

1 Relational Data Model

Informationslogistik Unit 5: Data Integrity & Functional Dependency

CSE 562 Database Systems

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

The Relational Data Model. Functional Dependencies. Example. Functional Dependencies

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

Schema Refinement: Dependencies and Normal Forms

Design Theory for Relational Databases

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

The Relational Data Model

RELATIONAL DATA MODEL: Relational Algebra

RELATIONAL QUERY LANGUAGES

Introduction to Databases, Fall 2003 IT University of Copenhagen. Lecture 4: Normalization. September 16, Lecturer: Rasmus Pagh

Lecture #8 (Still More Relational Theory...!)

Relational Database Design (II)

WEEK 3. EE562 Slides and Modified Slides from Database Management Systems, R.Ramakrishnan 1

Schema Refinement: Dependencies and Normal Forms

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

Relational Database Design. Announcements. Database (schema) design. CPS 216 Advanced Database Systems. DB2 accounts have been set up

18. Relational Database Design

Relational Model and Relational Algebra

CS2255 DATABASE MANAGEMENT SYSTEMS QUESTION BANK UNIT I

Fundamentals of Database Systems

In This Lecture. Normalisation to BCNF. Lossless decomposition. Normalisation so Far. Relational algebra reminder: product

Relational Query Languages

Introduction to Database Design, fall 2011 IT University of Copenhagen. Normalization. Rasmus Pagh

CSCI 403: Databases 13 - Functional Dependencies and Normalization

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 10-2

Part II: Using FD Theory to do Database Design

Announcements. CSCI 334: Principles of Programming Languages. Exam Study Session: Monday, May pm TBL 202. Lecture 22: Domain Specific Languages

Databases Relational algebra Lectures for mathematics students

Schema Refinement and Normal Forms

Functional Dependencies and Normalization for Relational Databases Design & Analysis of Database Systems

Selection and Projection

NORMAL FORMS. CS121: Relational Databases Fall 2017 Lecture 18

Relational Algebra. Relational Query Languages

Database Constraints and Design

Answer Key for Exam II Computer Science 420 Dr. St. John Lehman College City University of New York 18 April 2002

Lecture 5 Design Theory and Normalization

CAS CS 460/660 Introduction to Database Systems. Relational Algebra 1.1

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

CSC 261/461 Database Systems Lecture 13. Fall 2017

Combining schemas. Problems: redundancy, hard to update, possible NULLs

Informationslogistik Unit 4: The Relational Algebra

CS352 Lecture - Conceptual Relational Database Design

CS352 Lecture - Conceptual Relational Database Design

Lecture 4. Database design IV. INDs and 4NF Design wrapup

Exam I Computer Science 420 Dr. St. John Lehman College City University of New York 12 March 2002

More Normalization Algorithms. CS157A Chris Pollett Nov. 28, 2005.

V. Database Design CS448/ How to obtain a good relational database schema

SCHEMA REFINEMENT AND NORMAL FORMS

Midterm Exam (Version B) CS 122A Spring 2017

Transcription:

Relational Model and Relational Algebra A Short Review Class Notes - CS582-01 Tran Cao Son January 12, 2002 0.1 Basics The following definitions are from the book [1] Relational Model. Relations are tables representing information. Columns are headed by attributes.; each attribute has an associated domain (also: data type). Rows are called tuples, and a tuple has one component for each attribute of the relation. Example: a relation about movies 1 Title Year Length Type Harry Porter 2001 180 Color Gone with the wind 1938 125 Black and White Snow White 1950 90 Color The Movie Relation Relation schema: The name of the relation and the set of attributes for the relation. Example: Movie(T itle, Y ear, Length, T ype) is the relation schema of a relation named Movie (table above) and the set of attributes {T itle, Y ear, Length, T ype}. Tuples: Each row of the relation is a tuple. In the above is a tuple. (HarryP orter, 2001, 180, Color) Relation Instances: the set of tuples belonging to the relation. 1 Data are invented to illustrate the concepts. They might or might not be accurate. 1

Functional Dependencies. A functional dependency is of the form A 1... A n B. It states that tuples agree on the values of the attributes A 1,..., A n must also agree on the value of B. Keys. A set of attributes {A 1,..., A n } is a key of a relation R if it functionally determines all other attributes, and none of its proper subsets functionally determines all other attributes (i.e., it is minimal) A set of attributes that contains a key is a superkey. Rules to derive new functional dependencies Reflexivity: If {B 1,..., B m } {A 1,..., A n } then A 1... A n B 1... B m. Augmentation: If A 1... A n B 1... B m then A 1... A n C 1... C k B 1... B m C 1... C k. Transitivity: If A 1... A n B 1... B m and B 1... B m C 1... C k then A 1... A n C 1... C k. Closure of Attributes. {A 1,..., A n } + = {A A 1... A n A}. Non-trivial Functional Dependency. A 1... A n B 1... B m in nontrivial if at least on of the B s is not among the A s and completely nontrivial if none of the B s is one of the A s. BCNF and Third Normal Forms BCNF: R is in BCNF if for every nontrivial functional dependency A 1... A n B 1... B m of R, {A 1,..., A n } is a superkey for R. Decomposing into BCNF: See algorithm in book. Third Normal Form (or 3NF): R is in 3NF if for every nontrivial functional dependency A 1... A n B 1... B m of R, {A 1,..., A n } is a superkey for R or B is part of some key. Decomposing into 3NF: See algorithm in book. 2

Multivalued Dependencies and Fourth Normal Form A multivalued dependency is of the form A 1... A n B 1... B m. It states that for each pair of tuples t and u of R that agree on the values of the attributes A 1,..., A n we can find in R some tuple r that agrees 1. with both t and u on the A s, 2. with t on the A s, and 3. with u on the attributes that are not among the A s or B s. Rules to derive new multivalued dependencies Trivial: If A 1... A n B 1... B m then A 1... A n C 1... C k where {C 1,..., C k } {A 1,..., A n } {B 1,..., B m }. Transitivity: If A 1... A n B 1... B m and B 1... B m C 1... C k then A 1... A n C 1... C k. Completementation: If A 1... A n B 1... B m then A 1... A n C 1... C k where {C 1,..., C k } = AR \ ({A 1,..., A n } {B 1,..., B m }) and AR is the set of attributes of R. FD implication: If A 1... A n B 1... B m then A 1... A n B 1... B m. Non-trivial multivalued Dependency. A 1... A n B 1... B m in nontrivial if none of the B s is among the A s and {A 1,..., A n } {B 1,..., B m }) is not the set of all attributes of R. Fourth Normal Form R is in 4NF if for every nontrivial multivalued dependency A 1... A n B 1... B m for R, {A 1... A n } is a superkey. Relational Algebra. model. This algebra is an important form of query language for the relational The operators of the relational algebra: divided into the following classes: 1. Set operators: union, intersection, and set difference 2. Operators that remove part of the relation: projection or selection 3. Operatosr that combine part of the relation: cartesian product or joint 4. Renaming operators: rename the schema of the relation 3

0.2 Set operators Union ( ): R S represents a new relation whose tuples are either tuples belonging to R, to S, or both. Set difference (\): not to S. Intersection ( ) S. R \ S represents a new relation whose tuples are tuples belonging to R but : R S represents a new relation whose tuples are tuples belonging to R and Note: Set operators only work on relations with the same schema. Example 1 Let R be the following relation: and S be the following relation: Then: R S is R S is 2 3 4 1 3 4 4 3 4 2 3 4 1 3 4 4 3 4 4

and R \ S is NOTE: If the schema of S changes, say S(A1, B1, C1) then all of the three operations (,, \) will yield the empty relation. 0.3 Operators that remove part of the relation Projection (π) This operation removes some columns from a relation. We write π A1,...,A k (R) and the result is a new relation that has only the columns A 1,..., A k of R and whose schema is the set of attributes {A 1,..., A k } of the relation R. For the relation R in Example 1, π A,B (R) is the relation: A B 1 2 2 1 3 2 4 1 Selection (σ) The operation selects some tuples from the current relation and defines a new relation. σ C (R) represents a new relation that has tuples belonging to R and each of them satisfying the conditional expression (or condition) C. C is a conditional expression constructed from attributes of R or constants. For example, A < B + C would be a valid conditional expression with respect to the relation R in Example 1. For the relation R in Example 1, σ A<B+C (R) is the following relation: 0.4 Operators that combine relations Cartesian Product ( ) Given two relations R and S. The Cartesian product R S is the set of pairs that can be formed by chossing the first element of the pair to be any element of R and the second an element of S. Example 2 Let R be the following relation: 5

and S be the following relation: A D 2 3 2 1 Then: R S is A.R B C A.S D 2 3 2 1 2 3 2 3 2 1 2 1 2 1 2 1 Natural Joins ( ) Combine two relations but using only tuples that are matching in some way. Natural join considers only those pairs that have identical values on whatever attributes the two relations share. R S is a new relation whose schema contains the attributes in R and those attributes in S that are not in R. It has the tuples formed by pairing a tuple in R with a tuple in S provided that both have the same values on attributes shared by R and S. Example 3 Let R be the following relation: and S be the following relation: Then: R S is B D 2 3 3 1 6

D 3 3 The first tuple of R S is combined from the 1 st tuple of R and the 1 st tuple of S. The second tuple of R S is combined from the 3 st tuple of R and the 1 st tuple of S. For the second tuple of S, the value of B is 3 and none of the tuples in R has B = 3. So, no new tuple for R S can be formed using the second tuple of S. Theta-join This is a combination of Cartesian product and selection. R C S is defined by R C S = σ C (R S). 0.5 Renaming Operator Renaming (ρ): ρ S(A1,...,A k )(R) creates a new relation, named S, and attributes {A 1,..., A k } with all the tuples of R. Example 4 Let R be the following relation: Then, ρ T (M,N,P ) (R) is a new relation T with the following instance M N P NOTE: ρ S (R) only changes the name of the relation. 0.6 Combining Operations to Form Queries The operators of relational algebra allows us to form expressions of arbitrary complexity by applying operators to either a given relation or to the relations that are the result of applying operators to relations. Example like the theta-join operator, or something like π A,B (σ C>D (R S)) etc. References [1] J.D. Ullman and J. Widom. A First Course in Database Systems. Prentice Hall, 1997. 7