COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

Similar documents
CS 377 Database Systems

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

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

ECE 650 Systems Programming & Engineering. Spring 2018

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

The Relational Data Model and Relational Database Constraints

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

CS275 Intro to Databases

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

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

Relational Database Systems Part 01. Karine Reis Ferreira

ACS-3902 Fall Ron McFadyen 3D21 Slides are based on chapter 5 (7 th edition) (chapter 3 in 6 th edition)

CS 2451 Database Systems: Relational Data Model

The Relational Model

COSC344 Database Theory and Applications. COSC344 Lecture 15 1

Relational Data Model. Christopher Simpkins

Chapter 4. The Relational Model

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

CSC 742 Database Management Systems

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

Relational Model and Relational Algebra

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

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

The Relational Data Model and Relational Database Constraints

CSE 132A Database Systems Principles

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

The Relational Data Model (ALL the Vocabulary)

DBMS. Relational Model. Module Title?

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

Let s briefly review important EER inheritance concepts

Database Applications (15-415)

The Relational Model

The Relational Model and Relational Algebra

The Relational Data Model. Data Model

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

THE RELATIONAL DATABASE MODEL

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

The Relational Model 2. Week 3

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

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

The Relational Model

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

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

CS2300: File Structures and Introduction to Database Systems

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

Chapter 2 Introduction to Relational Models

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

The Relational Model. Chapter 3

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

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

CS317 File and Database Systems

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Running Example Tables name location

DATABASE TECHNOLOGY - 1DL124

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

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

8) A top-to-bottom relationship among the items in a database is established by a

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

The Relational Model of Data (ii)

Relational data model

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)

; Spring 2008 Prof. Sang-goo Lee (14:30pm: Mon & Wed: Room ) ADVANCED DATABASES

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

A database consists of several tables (relations) AccountNum

Database Technology Introduction. Heiko Paulheim

DATABASE DESIGN I - 1DL300

The data structures of the relational model Attributes and domains Relation schemas and database schemas

Relational Data Model

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Chapter 2: Intro to Relational Model

The Relational Model. Week 2

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

Chapter 1: Introduction

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

In This Lecture. The Relational Model. The Relational Model. Relational Data Structure. Unnamed and named tuples. New thing:scheme (and attributes)

The Relational Model Constraints and SQL DDL

CSIT5300: Advanced Database Systems

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Introduction to Databases

DATABASE MANAGEMENT SYSTEMS. UNIT I Introduction to Database Systems

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Chapter 2: Intro to Relational Model

CMP-3440 Database Systems

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple.

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

Supplier-Parts-DB SNUM SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens

Relational Model. CS 377: Database Systems

ADVANCED DATABASES ; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room ) Advanced DB Copyright by S.-g.

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

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

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

Chapter 3. The Relational database design

Conceptual Data Modeling

Transcription:

COSC344 Database Theory and Applications σ a= c (P) S P Lecture 3 The Relational Data π A, C (H) Model COSC344 Lecture 3 1

Overview Last Lecture Database design ER modelling This Lecture Relational model History Concepts Terminology Constraints Keys Integrity Source: Chapter 5 Next Lecture ER to Relational database mapping Relational algebra Source: Chapter 9.1, 8.1-8.2 COSC344 Lecture 3 2

Database Design Process miniworld DBMS-independent DBMS-specific Functional Requirements Functional Analysis High-level Transaction Specification Application Program Design Transaction Implementation Requirements Collection and Analysis data requirements Conceptual Design Conceptual Schema (in a high-level data model) Logical Design (Data Model Mapping) Logical (Conceptual) Schema (in a high-level data model) Physical Design Internal Schema Application Programs COSC344 Lecture 3 3

Categories of Data Models (revisit) High-level or conceptual data models close to the way most users perceive data, hide the details of the physical storage structures entity, attribute, relationship Low-level or physical data models storage details Representational or implementation data models bridge the gap between conceptual model and physical model the models used in traditional commercial DBMSs COSC344 Lecture 3 4

History of Database Models Hierarchical model The first database model Organize data into a tree-like structure Created by IBM in the 1960s Hierarchical schemas Model Division Divname... Department Dname... Network model The first specification was established at Conference on Data Systems Languages (CODASYL) in 1969 Relational Model Student Sname... Humanities Sciences Staff Stname... Network Model Invented by Codd in 1970 Relational Model Computer Science Mathematics The most popular model Allan Abbot Ali Anderson COSC344 Lecture 3 5

History of Relational Model Invented by E.F. Codd, IBM Research, in 1970 E.F.Codd, A Relational Model for Large Shared Data Banks, Communications of the ACM, 13:6, June 1970 Subsequently maintained and developed by Chris Date and Hugh Darwen among others Has mathematical theoretical basis Set theory First order predicate logic The dominant model for database Oracle, 1979 IBM DB2, 1983 Microsoft SQL server, 1989 Edgar F. Codd (1923-2003) Christopher J. Date Hugh Darwen COSC344 Lecture 3 6

The Relational Data Model The relational model has 3 core components: Objects (or relations) structure of the data organization Integrity enforcing constraints and rules Operators data manipulation COSC344 Lecture 3 7

Relational Model Concepts Represents the database as a collection of relations Informally, each relation resembles a table of values Row Represents a collection of related data values A fact that corresponds to a real-world entity or relationship Column Column headers represent attributes, and are used to help interpret the meanings of the values in each row Column values are derived from the domain of the corresponding attribute However, a table and a relation are not strictly equivalent COSC344 Lecture 3 8

Attributes, Tuples, Relations Formally, in the relational model, Relation -> table Tuple -> row Attribute -> column header COSC344 Lecture 3 9

A domain is a set of atomic values. Has a data type or format Domains Often useful to specify a name for a domain, for example integer real number date alphabetic character string NZ passport number IRD number Address COSC344 Lecture 3 10

Relation Schema A relation schema R, denoted by R(A 1, A 2,..., A n ), is made up of a relation name R and a set of attributes (A 1, A 2,..., A n ). Each attribute A i is the name of a role played by some domain D in the relation schema R D is called the domain of A i Is denoted by dom(a i ). The degree of a relation is the number of attributes n of its relation schema. COSC344 Lecture 3 11

Relation Schema Example STUDENT(Name, IRD, HomePhone, Address, OfficePhone, Age, GPA) What is the relation name? What is the degree of the relation? What are the attributes? List each dom(a i ). STUDENT Name IRD Home Phone Address Office Phone Age GPA COSC344 Lecture 3 12

Relation Schema (continued) A relation (or relation state) r of the relation schema R(A 1, A 2,..., A n ), also denoted by r(r), is a set of n-tuples r = {t 1, t 2,..., t k }. Each n-tuple t is a mapping from R to D, and D is the union of the attribute domains. A tuple can be considered as a set of (<attribute>,<value>) pairs, where each pair gives the value of the mapping from an attribute A i to a value v i from dom(a i ). Possible for several attributes to have the same domain. The attributes indicate different roles or interpretations for the domain. COSC344 Lecture 3 13

Characteristics of Relations Ordering of tuples in a relation Yes/No? Ordering of values within a tuple Yes/No? Values in the tuples First normal form - i.e. atomic can t be decomposed How to represent multi-valued attributes? How to represent composite attributes? NULL Unknown May not apply COSC344 Lecture 3 14

Constraints Relational Model Constraints Restrictions on the actual values in the database state Derived from the rules in the miniworld that the database represents Type of constraints in relational database Domain constraints Key constraints and constraints on NULL Integrity constraints Semantic integrity constraints Functional dependency constraints COSC344 Lecture 3 15

Domain Constraints Domain constraints specify that the value of each attribute must be an atomic value from the domain dom(a). Data types are usually associated with domains Standard numeric data types Integer Real number Strings, Boolean Date. Subrange of values Age is between 0 to 120 Enumerated data type Colour COSC344 Lecture 3 16

Key Constraints No two tuples can have the same combination of values for all their attributes. Superkey - a set of attributes such that for any two distinct tuples t 1 and t 2, t 1 [SK]!= t 2 [SK] Any set of attributes satisfying the above is a superkey One default superkey: the set of all its attributes Key Is a superkey removing any of the attributes from a Key leaves a set of attributes that is not a superkey (minimal superkey) A relation schema may have more than one key. Each of the keys is called a candidate key. Typically one candidate key is designated as primary key. COSC344 Lecture 3 17

Example Schema COSC344 Lecture 3 18

Integrity Constraints Integrity constraints: Specified on a database schema Are expected to hold on every valid database state of the schema Types Domain, Key, NOT NULL Entity Integrity constraint No primary key values can be NULL Referential Integrity constraint Specified between two relations Maintains consistency among tuples in two relations Informally, it states that a tuple in one relation that refers to another relation must refer to an existing tuple in that relation. COSC344 Lecture 3 19

Example Student Tutors Name Dan Emma Frank Gina Hamish Ian Jo NULL Home Phone Address 479001 ertyu 479002 qwer 479002 qwer 479002 qwer 479005 tyufgd 479006 ghjgjh 479006 ghjghj 479008 iuwer Paper Stream Senior Student Student Rep COSC344 A Dan NULL COSC344 B Emma NULL COMP112 A Frank Hamish COMP112 B Emma Ian COMP112 C Gina Jo COMP112 D Dan Pete COMP160 A Frank NULL COSC344 Lecture 3 20

Foreign Keys A set of attributes FK in relation schema R 1 is a foreign key of R 1 that references relation R 2 if it satisfies these conditions: The attributes in FK have the same domain(s) as the primary key attributes PK of R 2 ; the attributes FK are said to refer to the relation R 2. A value of FK in a tuple t 1 of the current state r 1 (R 1 ) either occurs as a value of PK for some tuple t 2 in the current state r 2 (R 2 ) or is NULL. In the former case, t 1 [FK] = t 2 [PK], and we say that the tuple t 1 refers to the tuple t 2. R 1 is called the referencing relation, and R 2 is called the referenced relation. COSC344 Lecture 3 21

Referential Integrity Revisited What are the referential integrity constraints of the example database? Can be shown in the schema diagram as directed arrows drawn from each foreign key to the primary key of the referenced relation. A foreign key can refer to its own relation. COSC344 Lecture 3 22

Referential Integrity Example COSC344 Lecture 3 23

Other Types of Constraints Semantic integrity constraints Example: the salary of an employee should not exceed the salary of the employee s supervisor. Enforced using trigger and assertion mechanism (will be discussed later) Functional dependency constraints Establish a functional relationship among two sets of attributes X and Y Will be discussed in later lectures COSC344 Lecture 3 24

Dealing with Constraint Violations (1) Three basic operations that can change the state of relations in the database Insert Delete Update The Insert Operation Can violate most constraints If an insertion violates one or more constraints, the default option is to reject the insertion. COSC344 Lecture 3 25

Dealing with Constraint Violations (2) The Delete Operation Can violate only referential integrity constraint Occurs if the tuple being deleted is referenced by foreign keys from other tuples in the database. Options Reject the deletion (restrict) Attempt to cascade (or propagate) the deletion by deleting tuples that reference the tuple that is being deleted (cascade). Modify the referencing attributes (Set NULL or Set default) The Update Operation Can violate most constraints Options: combination of options for dealing with violations in Insert and Delete operations. COSC344 Lecture 3 26

Question to Ponder How do you turn an ER diagram into a relational model? COSC344 Lecture 3 27