The Relational Model. csc343, Introduction to Databases Diane Horton, Michelle Craig, and Sina Meraji Fall 2017

Similar documents
The Relational Model. csc343, Introduction to Databases Diane Horton Fall 2014

Relational Model Concepts

The Semi-Structured Data Model. csc343, Introduction to Databases Diane Horton originally based on slides by Jeff Ullman Fall 2017

Relational Algebra. csc343, Introduction to Databases Diane Horton, Michelle Craig, and Sina Meraji Fall 2017

Chapter 4. The Relational Model

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

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

Chapter 2 Introduction to Relational Models

Introduction to Database Systems. The Relational Data Model

Introduction to Database Systems. The Relational Data Model. Werner Nutt

CS2300: File Structures and Introduction to Database Systems

CS 377 Database Systems

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

Let s briefly review important EER inheritance concepts

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

Lecture 1: Conjunctive Queries

Design Theory for Relational Databases

CSE 132A Database Systems Principles

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Introduction to Relational Database Systems Fall 2016 Lecture 1

The Relational Model

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

Chapter 5. Relational Model Concepts 5/2/2008. Chapter Outline. Relational Database Constraints

Chapter 5. Relational Model Concepts 9/4/2012. Chapter Outline. The Relational Data Model and Relational Database Constraints

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

CS275 Intro to Databases

The Relational Model

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

SQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji. Winter 2018

CS 2451 Database Systems: Relational Data Model

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

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

A database consists of several tables (relations) AccountNum

CS317 File and Database Systems

SQL: Data Manipulation Language. csc343, Introduction to Databases Diane Horton Winter 2017

The Relational Data Model and Relational Database Constraints

Part II: Using FD Theory to do Database Design

Chapter 2: Intro to Relational Model

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

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

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

Relational Model. CS 377: Database Systems

Database Systems. Basics of the Relational Data Model

Lecture 16. The Relational Model

ECE 650 Systems Programming & Engineering. Spring 2018

Relational Model, Relational Algebra, and SQL

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Databases. Jörg Endrullis. VU University Amsterdam

CSC 261/461 Database Systems Lecture 13. Fall 2017

Chapter 5. The Relational Data Model and Relational Database Constraints. Slide 5-١. Copyright 2007 Ramez Elmasri and Shamkant B.

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

CSC 742 Database Management Systems

Relational Algebra Part I. CS 377: Database Systems

RELATIONAL QUERY LANGUAGES

Relational Databases

2.1 Sets 2.2 Set Operations

SQL Simple Queries. Chapter 3.1 V3.01. Napier University

BIRKBECK (University of London)

Chapter 1: Introduction

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

From ER Diagrams to the Relational Model. Rose-Hulman Institute of Technology Curt Clifton

Database Applications (15-415)

Relational Data Model. Christopher Simpkins

The Relational Model

The Relational Model

The Relational Model Constraints and SQL DDL

Relational Design: Characteristics of Well-designed DB

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

CSE 530A. ER Model to Relational Schema. Washington University Fall 2013

CSC Discrete Math I, Spring Sets

The Relational Data Model (ALL the Vocabulary)

Chapter 2: Intro to Relational Model

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

Relational Data Model ( 관계형데이터모델 )

Informatics 1: Data & Analysis

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

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

Informatics 1: Data & Analysis

CS425 Midterm Exam Summer C 2012

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

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

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

Relational Data Model

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

Databases The theory of relational database design Lectures for m

Review The Big Picture

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 2: Relations and SQL. September 5, Lecturer: Rasmus Pagh

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out end of week start early!

01/01/2017. Chapter 5: The Relational Data Model and Relational Database Constraints: Outline. Chapter 5: Relational Database Constraints

CS Reading Packet: "Introduction to the Relational Model and Relational Operations"

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

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

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

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until

Chapter 3. The Relational database design

Introduction to modeling

Review for Exam 1 CS474 (Norton)

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

Transcription:

The Relational Model csc343, Introduction to Databases Diane Horton, Michelle Craig, and Sina Meraji Fall 2017

Recap! The relational model is based on the concept of a relation or table.! Two example relations: Teams Name Home Field Coach Rangers Runnymede CI Tarvo Sinervo Ducks Humber Public Tracy Zheng Choppers High Park Ammar Jalali Games Home team Away team Home goals Away goals Rangers Ducks 3 0 Ducks Choppers 1 1 Rangers Choppers 4 2 Choppers Ducks 0 5 2

Relations in Math! A domain is a set of values.! Suppose D1, D2,... Dn are domains. The Cartesian product D1 x D2 x... x Dn is the set of all tuples <d1, d2,..., dn> such that d1 D1, d2 D2,..., dn Dn. I.e., every combination of a value from D1, a value from D2 etc.! A (mathematical) relation on D1, D2,... Dn is a subset of the Cartesian product. 3

Example! Example of a mathematical relation: Let A = {p, q, r, s}, B = {1, 2, 3} and C = {100, 200}. R = {<q, 2, 100>, <s, 3, 200>, <p, 1, 200>} is a relation on A, B, C.! Our database tables are relations too.! Example: {<Rangers, Ducks, 3, 0>, <Ducks, Choppers, 1, 1>, <Rangers, Choppers, 4, 2>, <Choppers, Ducks, 0, 5>} 4

Relation schemas vs instances! Schema: definition of the structure of the relation. Example: Teams have 3 attributes: name, home field, coach. No two teams can have the same name.! Notation for expressing a relation s schema Teams(Name, HomeField, Coach)! Instance: particular data in the relation.! Instances change constantly; schemas rarely.! Conventional databases store the current version of the data. Databases that record the history are called temporal databases. 5

Terminology Teams Name Home Field Coach Rangers Runnymede CI Tarvo Sinervo Ducks Humber Public Tracy Zheng Choppers High Park Ammar Jalali Crullers WTCS Anna Liu! relation (table)! attribute (column)! tuple (row)! arity of a relation: number of attributes! cardinality of a relation: number of tuples 6

Relations are sets! A relation is a set of tuples, which means: there can be no duplicate tuples order of the tuples doesn't matter! In another model, relations are bags a generalization of sets that allows duplicates.! Commercial DBMSs use this model.! But for now, we will stick with relations as sets. 7

Database schemas and instances! Database schema: a set of relation schemas! Database instance: a set of relation instances 8

A schema for our league data Teams(name, homefield, coach) Games(hometeam, awayteam, homegoals, awaygoals)! Can there be >1 team with the same name? Didn t happen in our dataset, but could it? That s up to the league, not us!! Suppose the league wants to allow multiple teams with same name multiple teams with same home field! The schema allows it: nothing says otherwise.! But what if the league wants to disallow multiple teams with the same name and home field?

Constraining the data! More formally: tuples t1 and t2 such that (t1.name = t2.name) (t1.homefield = t2.homefield)! Implication: If we know the values for {name, homefield}, we can look up exactly one team in the relation.! I.e., attributes {name, homefield} uniquely identify tuples in this relation.! We say that {name, homefield} is a superkey for relation Teams. 10

Superkeys! Informally: A superkey is a set of one or more attributes whose combined values are unique. I.e., no two tuples can have the same values on all of these attributes.! Formally: If attributes a1, a2,, an form a superkey for relation R, tuples t1 and t2 such that (t1.a1 = t2.a1) (t1.a2 = t2.a2) (t1.an = t2.an)

Example! Course(dept, number, name, breadth) One tuple might be < csc, 343, Introduction to Databases, True>! Suppose our knowledge of the domain tells us that no two tuples can have the same value for dept and number.! This means that {dept, number} is a superkey.! This is a constraint on what can go in the relation.! Create an instance of Course that violates it.! Does every relation have a superkey?

Keeping it minimal! If {dept, number} is a superkey, then so is {dept, number, name}. This follows from the definition.! But we are more interested in a minimal set of attributes with the superkey property. Minimal in the sense that no attributes can be removed from the superkey without making it no longer a superkey.

Keys! key: a minimal superkey.! In the schema, by convention we often underline a key.! Aside: The term superkey is related to the term superset. A superkey is a superset of some key. (Not necessarily a proper superset.)! Can a relation have more than one key?

Coincidence vs key! If a set of attributes is a key for a relation: It does not mean merely that there are no duplicates in a particular instance of the relation It means that in principle there cannot be any. Only a domain expert can determine that.! Often we invent an attribute to ensure all tuples will be unique. This predates databases. E.g., SIN, ISBN number.! A key defines a kind of integrity constraint. 15

Primary key??! Some of you have heard the term primary key.! This is specific to SQL and we ll learn about it later. 16

Example: Movies schema handout, Q1-6 17

References between relations! Relations often refer to each other.! Example: In the Roles relation, the tuple about Han Solo needs to say he is played by Ford.! Rather than repeat information already in the Artists table, we store Ford s key.! If aid is a key for Artists, does that mean a particular aid can appear only once in Roles?? 18

Foreign keys! The referring attribute is called a foreign key because it refers to an attribute that is a key in another table.! This gives us a way to refer to a single tuple in that relation.! A foreign key may need to have several attributes. 19

Declaring foreign keys! A bit of notation: R[A] R is a relation and A is a list of attributes in R. R[A] is the set of all tuples from R, but with only the attributes in list A.! We declare foreign key constraints this way: R1[X] R2[Y] X and Y may be lists of attributes, of same arity Y must be a key in R2! Example: Roles[mID] Movies[mID] 20

Example: Movies schema handout, Q7-9 21

Referential integrity constraints! These R1[X] R2[Y] relationships are a kind of referential integrity constraint or inclusion dependency.! Not all referential integrity constraints are foreign key constraints.! For example, we could say Artists[aID] Roles[aID] Here we are not referring to a unique tuple.! R1[X] R2[Y] is a foreign key constraint iff Y is a key for relation R2. 22

Designing a schema! Mapping from the real world to a relational schema is surprisingly challenging and interesting.! There are always many possible schemas.! Two important goals: Represent the data well. For example, avoid constraints that prevent expressing things that occur in the domain. Avoid redundancy.! Later, we ll learn some elegant theory that provides sound principles for good design. 23

What s next! We will learn how to use SQL to define a database s structure, put data in it, and write queries on it.! First we ll learn how to write queries in relational algebra. Relational algebra is the foundation for SQL. Other important concepts, like query optimization, are defined in terms of RA. 24