CS 377 Database Systems

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

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

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

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

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

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

The Relational Data Model and Relational Database Constraints

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

CS275 Intro to Databases

CSE 132A Database Systems Principles

CS2300: File Structures and Introduction to Database Systems

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

Let s briefly review important EER inheritance concepts

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

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

CSC 742 Database Management Systems

ECE 650 Systems Programming & Engineering. Spring 2018

A database consists of several tables (relations) AccountNum

Relational Data Model. Christopher Simpkins

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

The Relational Data Model and Relational Database Constraints

The Relational Data Model (ALL the Vocabulary)

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

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

Relational Model Concepts

CS 2451 Database Systems: Relational Data Model

Chapter 4. The Relational Model

Relational Model and Relational Algebra

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

UNIT 2 RELATIONAL MODEL

Chapter 3 Outline. Relational Model Concepts. The Relational Data Model and Relational Database Constraints Database System 1

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

The Relational Model

THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E)

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

Relational Model. CS 377: Database Systems

The Relational Data Model. Data Model

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

DBMS. Relational Model. Module Title?

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

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

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

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

Relational Database Systems Part 01. Karine Reis Ferreira

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 Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

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

The Relational Model 2. Week 3

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Database Systems Relational Model. A.R. Hurson 323 CS Building

DATABASE TECHNOLOGY - 1DL124

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

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

The Relational Model of Data (ii)

The Relational Model. Week 2

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

The Relational Model

Introduction to Database Systems. The Relational Data Model

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

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

Relational data model

The Relational Model and Relational Algebra

Database Applications (15-415)

The Relational Model. Chapter 3

Running Example Tables name location

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

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

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

Databases. Jörg Endrullis. VU University Amsterdam

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

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

DATABASE DESIGN I - 1DL300

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

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

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

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

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

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

THE RELATIONAL DATABASE MODEL

Introduction to Database Management Systems

Database Systems ( 資料庫系統 )

CSC 453 Database Technologies. Tanu Malik DePaul University

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

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

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

Relational Data Model

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

Chapter 2 Introduction to Relational Models

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

DATABASE TECHNOLOGY. Spring An introduction to database systems

Chapter 10. Normalization. Chapter Outline. Chapter Outline(contd.)

CS317 File and Database Systems

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

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

Informal Design Guidelines for Relational Databases

3 February 2011 CSE-3421M Test #1 p. 1 of 14. CSE-3421M Test #1. Design

Chapter 1: Introduction

Chapter 8 INTEGRITY 1

Transcription:

CS 377 Database Systems Relational Data Model Li Xiong Department of Mathematics and Computer Science Emory University 1

Outline Relational Model Concepts Relational Model Constraints Relational Database and operations 2

Relational Model First formal database model Introduced by Codd in "A Relational Model for Large Shared Data Banks," Communications of the ACM, June 1970. First commercial implementations available in early 1980s Based on the concept of a mathematical relation and has theoretical basis in set theory and firstorder predicate logic. Other models: hierarchical model, network model 3

INFORMAL DEFINITIONS RELATION: A table of values A relation may be thought of as a set of rows. A relation may alternately be thought of as a set of columns. Each row represents a fact that corresponds to a real-world entity or relationship. Table name and column names help interpret the meaning of the values 4

FORMAL DEFINITIONS Relation Schema The table is called a relation, a row is a tuple, a column header is an attribute Relation Schema R (A 1, A 2,...A n ) Made up of a relation name R and a set of attributes A 1, A 2,...A n Degree (or arity) of a relation is the number of attributes n of its relational schema E.g. STUDENT (Name, SSN, HomePhone, Address, OfficePhone, Age, GPA) Each attribute A i has a domain dom(a i ) that defines the possible values of the attribute by a data-type or a format E.g. The domain of SSN is the set of 9 digit numbers defined as: ddd-dd-dddd where each d is a decimal digit. 5

FORMAL DEFINITIONS Relation A relation (or relation state) r of the relation schema R (A 1, A 2,...A n ), r(r), is a set of tuples r = {t 1, t 2,..., t m } A tuple t is an ordered set of n values t =<v 1, v 2,..., v n >, where each value v i, 1 i n, is an element of dom(a i ) or a special NULL value E.g. < Benjamin Bayer", 305-61-2435, 373-1616, 2918 Bluebonnet Lane, null, 19, 3.21> is a tuple belonging to the STUDENT relation. 6

Mathematical Definitions A relation r(r) is a mathematical relation of degree n on the domains dom(a 1 ), dom(a 2 ),..., dom(a n ), which is a subset of the Cartesian product of the domains that define R: r(r) (dom(a 1 ) dom(a 2 )... dom(a n )) The Cartesian product is the direct product of the sets of values of all domains: dom (A 1 ) dom (A 2 )... dom(a n ) The total number of tuples in the Cartesian product is: dom (A 1 ) dom (A 2 )... dom(a n ) Current relation state reflects only the valid tuples that represent a particular state 7

CHARACTERISTICS OF RELATIONS Ordering of tuples in a relation r(r) A relation is a set of tuples which are not ordered Ordering of attributes The attributes in R(A 1, A 2,..., A n ) and the values in t=<v 1, v 2,..., v n > are an ordered list in our definition Alternative definition: tuple 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 ) Values in a tuple All values are considered atomic (flat relational model with first normal form assumption) what about multi-valued attributes and composite attributes? A special null value is used to represent values that are unknown or inapplicable to certain tuples. 8

DEFINITION SUMMARY Informal Terms Table Column Row Values in a column Table Definition Formal Terms Relation Attribute Tuple Domain Relation Schema 9

Relational Model Notation Relation schema R of degree n: R(A 1, A 2,..., A n ) Relation names: Q, R, S Relations: q, r, s Tuples: t, u, v tuple t in a relation r(r): t = <v 1, v 2,..., v n >, v i is the value corresponding to attribute A i Component values of tuples: t[a i ] and t.a i refer to the value v i in t for attribute A i t[a u, A w,..., A z ] and t.(a u, A w,..., A z ) refer to the subtuple of values <v u, v w,..., v z > from t corresponding to the attributes specified in the list 10

Outline Relational Model Concepts Relational Model Constraints Relational Database and operations 11

Relational Model Constraints Constraints Restrictions on the actual values in a database state Inherent model-based constraints or implicit constraints Inherent in the data model E.g. no duplicate tuples Schema-based constraints or explicit constraints Can be directly expressed in schemas of the data model Application-based or semantic constraints or business rules Cannot be directly expressed in schemas, expressed and enforced by application program E.g. the max. no. of hours per employee for all projects he or she works on is 56 hrs per week 12

Schema-based constraints Domain constraints Key constraints Entity integrity constraints Referential integrity constraints 13

Domain Constraints The value of each attribute A must be an atomic value from the domain dom(a) Typical data types associated with domains: Numeric data types for integers and real numbers Characters Booleans Fixed-length strings Variable-length strings Date, time, timestamp Money Other special data types 14

Key Constraints No two tuples can have the same combination of values for all their attributes. Superkey No two distinct tuples in any state r of R can have the same value for SK Key Superkey of R Removing any attribute A from K leaves a set of attributes K that is not a superkey of R any more 15

Key Constraints and Constraints on NULL Values (cont d.) Key satisfies two properties: Two distinct tuples in any state of relation cannot have identical values for (all) attributes in key Minimal superkey Cannot remove any attributes and still have uniqueness constraint in above condition hold 16

Key Constraints and Constraints on NULL Values (cont d.) Candidate key Relation schema may have more than one key Primary key of the relation Designated among candidate keys Underline attribute Other candidate keys are designated as unique keys 17

Key Constraints and Constraints on NULL Values (cont d.) 18

Key Constraints Superkey of R: A set of attributes SK of R such that no two tuples in any valid relation instance r(r) will have the same value for SK. For any distinct tuples t1 and t2 in r(r), t1[sk] t2[sk]. {Licence_number}, {License_number, Make}, {Engine_serial_number, Make} Key of R: A "minimal" superkey; that is, a superkey K such that removal of any attribute from K results in a set of attributes that is not a superkey. Key1 = {License_number}, Key2 = {Engine_serieal_number} Is {Engine_serial_number, Make} a key? If a relation has several keys, each is called a candidate key, and one is chosen arbitrarily to be the primary key. The primary key attributes are underlined. 19

Entity Integrity Entity Integrity: The primary key attributes PK of each relation schema R cannot have null values in any tuple of r(r). t[pk] null for any tuple t in r(r) Primary key values are used to identify the individual tuples. Note: Other attributes of R may be similarly constrained to disallow null values, even though they are not members of the primary key. 20

Referential Integrity Referential integrity: a tuple in one relation that refers to another relation must refer to an existing tuple in that relation. Formally A set of attributes FK in relation schema R1 is a foreign key of R1 that references relation R2 if: FK have the same domains as the primary key attributes PK of R2 The value of FK in the current state of R 1 can be either: (1) a value of PK in the current state of R 2 : t 1 [FK] = t 2 [PK]. (2) a null R1 is the referencing relation and R2 is the referenced relation. A tuple t 1 in R 1 is said to reference a tuple t 2 in R 2 if t 1 [FK] = t 2 [PK]. A referential integrity constraint can be displayed in a relational database schema as a directed arc from R 1.FK to R 2. 21

5.5 22

23

24

25

Outline Relational Model Concepts Relational Model Constraints Relational Database and operations 26

Relational Databases and Relational Database Schemas Relational database schema S Set of relation schemas S = {R 1, R 2,..., R m } Set of integrity constraints IC Relational database state Set of relation states DB = {r 1, r 2,..., r m } Each r i is a state of R i such that the r i relation states satisfy integrity constraints specified in IC Invalid state Does not obey all the integrity constraints Valid state Satisfies all the constraints in the defined set of integrity constraints IC 27

Operations in a Relational Database Basic operations that change the states of relations in the database: Insert Delete Update (or Modify) 28

The Insert Operation Provides a list of attribute values for a new tuple t to be inserted into a relation R Can violate any of the four types of constraints Default option is to reject the insertion 29

The Delete Operation Can violate only referential integrity If tuple being deleted is referenced by foreign keys from other tuples, e.g. delete a tuple from department Restrict Reject the deletion Cascade Propagate the deletion by deleting tuples that reference the deleted tuple Set null or set default Modify the referencing attribute values that cause the violation 30

The Update Operation Necessary to specify a condition on attributes of relation Select the tuple (or tuples) to be modified If attributes to be updated not part of a primary key nor of a foreign key Usually causes no problems Updating a primary/foreign key Similar issues as with Insert/Delete 31

In-Class Exercise Consider the following relations for a database that keeps track of student enrollment in courses and the books adopted for each course: STUDENT(SSN, Name, Major, Bdate) COURSE(Course#, Cname, Dept) ENROLL(SSN, Course#, Quarter, Grade) BOOK_ADOPTION(Course#, Quarter, Book_ISBN) TEXT(Book_ISBN, Book_Title, Publisher, Author) Draw a relational schema diagram specifying the foreign keys for this schema. 32