The Relational Data Model

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Database Systems Chapter 5 ITM 354. Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations.
Chapter 5 The Relational Data Model and Relational Database Constraints.
CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian.
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
1 Lecture 04 The relational data Model, Relational Constraints 1.
The Relational Data Model 1.Relational Model Concepts 2.Characteristics of Relations 3.Relational Integrity Constraints 3.1Key Constraints 3.2Entity Integrity.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and SQL.
Topic 5 The Relational Data Model and Relational Database Constraints Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
The Relational Data Model and Relational Database Constraints
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1 Week4 Relational Model and Relational Database Constraints Relational Model Concepts.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Chapter 6 The Relational Data Model and the Relational Algebra.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 The Basic Relational Model.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
1 CSBP430 – Database Systems Chapter 7 - The Relational Data Model Elarbi Badidi College of Information Technology United Arab Emirates University
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 5 The Relational Data Model and Relational Database Constraints Slide 1- 1.
The Relational Data Model and Relational Database Constraints
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
The Relational Data Model and Relational Database Constraints.
4/28/2017 Chapter 5 The Relational Data Model and Relational Database Constraints.
Chapter 3 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Copyright © 2004 Pearson Education, Inc.
CSE202 Database Management Systems
4/20/2018.
The Relational Data Model and Relational Database Constraints
Lecture # 13 (After 1st Exam)
376a. Database Design Dept. of Computer Science Vassar College
Relational Integrity Constraints
Chapter (7) The relational Data Model, Relational Constraints, and the Relational Algebra Objectives Describe the basic principals of the relational model.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
CS4222 Principles of Database System
12/7/2018.
The Relational Data Model and Relational Database Constraints
2/28/2019 Chapter 5 The Relational Data Model and Relational Database Constraints.
4/8/2019.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
5/12/2019.
Copyright © 2004 Pearson Education, Inc.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
Presentation transcript:

The Relational Data Model Database Systems Chapter 5 The Relational Data Model 主講人:陳建源 研究室 :法401 Email: cychen07@nuk.edu.tw 日期:99/11/2

Outline 1.Relational Model Concepts 2.Relational Model Constraints and Relational Database Schemas 3.Update Operations and Dealing with Constraint Violations

1. Relational Model Concepts Basis of the model The relational Model of Data is based on the concept of a Relation The strength of the relational approach to data management comes from the formal foundation provided by the theory of relations We review the essentials of the formal relational model in this chapter In practice, there is a standard model based on SQL – this is described in Chapters 8 and 9

1. Relational Model Concepts A Relation is a mathematical concept based on the ideas of sets The model was first proposed by Dr. E.F. Codd of IBM in 1970 "A Relational Model for Large Shared Data Banks," Communications of the ACM, June 1970 The above paper caused a major revolution in the field of database management and earned Dr. Codd the coveted ACM Turing Award

1. Relational Model Concepts Informal Definitions RELATION: A table of values A relation may be thought of as a set of rows A relation may alternately be though of as a set of columns Each row of the relation may be given an identifier Each column typically is called by its column name or column header or attribute name

1. Relational Model Concepts Formal Definitions Domain D Set of atomic values Atomic Each value indivisible Specifying a domain Data type specified for each domain

1. Relational Model Concepts Formal Definitions The Schema of a Relation R (A1, A2, .....An) Relation schema R is defined over attributes A1, A2, .....An Each attribute Ai is the name of a role played by some domain D in the relation schema R e.g., A relation schema STUDENT(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA) Degree (or arity) of a relation Number of attributes n of its relation schema

1. Relational Model Concepts A relation r(R) is a subset of the Cartesian product of the domains that define R r(R)  (dom (A1)  dom (A2)  ....  dom(An)) e.g., Let S1 = {0,1}, S2 = {a,b,c} r(R) = {<0, a>, <0, b>, <1, c>} A relation may be regarded as a set of tuples (rows) r = {t1, t2, . . ., tm}. A tuple is an ordered set of values t = <v1, v2, . . ., vn>

1. Relational Model Concepts Cardinality Total number of values in domain Current relation state Relation state at a given time Reflects only the valid tuples that represent a particular state of the real world Attribute names Indicate different roles, or interpretations, for the domain

1. Relational Model Concepts R is also called the intension of a relation r is also called the extension of a relation The degree of a relation is the number of attributes n of its relation schema

1. Relational Model Concepts

1. Relational Model Concepts Definition summary Informal Terms Formal Terms Table Relation Column Attribute/Domain Row Tuple Values in a column Domain Table Definition Schema of Relation Populated Table Extension

1. Relational Model Concepts Characteristics of Relations Ordering of tuples in a relation r(R) The tuples are not considered to be ordered, even though they appear to be in the tabular form

1. Relational Model Concepts Characteristics of Relations Ordering of attributes in a relation schema R We will consider the attributes in R(A1, A2, ..., An) and the values in t=<v1, v2, ..., vn> to be ordered A more general alternative definition of relation does not require this ordering

1. Relational Model Concepts Characteristics of Relations Values in a tuple All values are considered atomic (indivisible) A special null value is used to represent values that are unknown or inapplicable to certain tuples e.g., OfficePhone for some students We refer to component values of a tuple t by t[Ai] = vi (the value of attribute Ai for tuple t) Similarly, t[Au, Av, ..., Aw] refers to the subtuple of t containing the values of attributes Au, Av, ..., Aw, respectively

1. Relational Model Concepts Relational Model Notation Relation schema R of degree n Denoted by R(A1, A2, ..., An) Uppercase letters Q, R, S Denote relation names Lowercase letters q, r, s Denote relation states Letters t, u, v Denote tuples

1. Relational Model Concepts Relational Model Notation Name of a relation schema: STUDENT Indicates the current set of tuples in that relation Notation: STUDENT(Name, Ssn, ...) Refers only to relation schema Attribute A can be qualified with the relation name R to which it belongs Using the dot notation R.A

1. Relational Model Concepts Relational Model Notation n-tuple t in a relation r(R) Denoted by t = <v1, v2, ..., vn> vi is the value corresponding to attribute Ai Component values of tuples: t[Ai] and t.Ai refer to the value vi in t for attribute Ai t[Au, Aw, ..., Az] and t.(Au, Aw, ..., Az) refer to the subtuple of values <vu, vw, ..., vz> from t corresponding to the attributes specified in the list

2.Relational Model Constraints Restrictions on the actual values in a database state Derived from the rules in the miniworld that the database represents Inherent model-based constraints or implicit constraints Inherent in the data model

2.Relational Model Constraints 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

2.Relational Model Constraints Domain Constraints Typically include: Numeric data types for integers and real numbers Characters Booleans Fixed-length strings Variable-length strings Date, time, timestamp Money Other special data types

2.Relational Model Constraints Relational Integrity Constraints Constraints are conditions that must hold on all valid relation instances Three main types of constraints: Key constraints Entity integrity constraints Referential integrity constraints

2.Relational Model Constraints Relational Integrity Constraints 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, i.e., for any distinct tuples t1 and t2 in r(R), t1[SK] <> t2[SK] Key of R A minimal superkey A superkey K such that removal of any attribute from K results in a set of attributes that is not a superkey

2.Relational Model Constraints Relational Integrity Constraints If a relation has several candidate keys, one is chosen arbitrarily to be the primary key The primary key attributes are underlined e.g, CAR(State, Reg#, SerialNo, Make, Model, Year) two keys, Key1 = {State, Reg#}, Key2 = {SerialNo} {SerialNo, Make} is a superkey but not a key

2.Relational Model Constraints Relational Integrity Constraints

2.Relational Model Constraints Relational Integrity Constraints Entity Integrity Relational database schema A set S of relation schemas that belong to the same database S is the name of the database, S = {R1, R2, ..., Rn} A relational database state DB of S A set of relation states DB = {r1, r2, . . ., rm} such that each ri is a state of Ri

Relational Integrity Constraints (cont.)

2.Relational Model Constraints

2.Relational Model Constraints

2.Relational Model Constraints Relational Integrity Constraints Entity Integrity The primary key attributes PK of each relation schema R in S cannot have null values in any tuple of r(R), i.e., t[PK] <> null for any tuple t in r(R)

2.Relational Model Constraints Relational Integrity Constraints Referential Integrity A constraint used to specify a relationship among tuples in two relations: the referencing relation and the referenced relation Tuples in the referencing relation R1 have attributes FK (called foreign key attributes) that reference the primary key attributes PK of the referenced relation R2

2.Relational Model Constraints Relational Integrity Constraints A tuple t1 in R1 is said to reference a tuple t2 in R2 if t1[FK] = t2[PK] A referential integrity constraint can be displayed in a relational database schema as a directed arc from R1.FK to R2 A foreign key can refer to its own relation e.g., the attribute SUPERSSN in EMPLOYEE refers to the supervisor of an employee

2.Relational Model Constraints

2.Relational Model Constraints Relational Integrity Constraints Other types of constraints Semantic integrity constraints May have to be specified and enforced on a relational database Use triggers and assertions More common to check for these types of constraints within the application programs e.g., the salary of an employee should not exceed the salary of the employee’s supervisor Transition constraints Used to deal with state changes in the database e.g., the salary of an employee can only increase

2.Relational Model Constraints Relational Integrity Constraints Other types of constraints Functional dependency constraint Establishes a functional relationship among two sets of attributes X and Y Value of X determines a unique value of Y State constraints Define the constraints that a valid state of the database must satisfy

3. Update Operations on Relations Three basic update operations INSERT a tuple DELETE a tuple MODIFY a tuple Integrity constraints should not be violated by the update operations

3. Update Operations on Relations Insert Insert can violate any of the four types of constraints Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, null, ‘1960-04-05’, ‘6357 Windy Lane, Katy, TX’, F, 28000, null, 4> into EMPLOYEE violates the entity integrity constraint (null for the primary key SSN) Insert <‘Alicia’, ‘J’, ‘Zelaya’, ‘999887777’, ‘1960-04-05’, ‘6357 Windy Lane, Katy, TX’, F, 28000, ‘987654321’, 4> into EMPLOYEE violates the key constraint because ‘999887777’ exists

3. Update Operations on Relations Delete The Delete operation can violate only referential integrity, if the tuple being deleted is referenced by the foreign keys from other tuples in the database Delete the EMPLOYEE tuple with SSN = ‘999887777’ is not acceptable, because tuples in WORKS_ON refer to this tuple Delete the EMPLOYEE tuple with SSN = ‘333445555’ result in even worse referential integrity violations

3. Update Operations on Relations Delete If tuple being deleted is referenced by foreign keys from other tuples Restrict Reject the deletion Cascade Propagate the deletion by deleting tuples that reference the tuple that is being deleted Set null or set default Modify the referencing attribute values that cause the violation

3. Update Operations on Relations Updating an attribute that is neither a primary key nor a foreign key usually causes no problems Modifying a primary key value is similar to deleting one tuple and inserting another in its place If a foreign key attribute is modified, the DBMS must make sure that the new value refers to an existing tuple in the referenced relation (or is null)

Summary Presented relational model concepts Definitions Characteristics of relations Discussed relational model constraints and relational database schemas Domain constraints’ Key constraints Entity integrity Referential integrity Described the relational update operations and dealing with constraint violations