1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.

Slides:



Advertisements
Similar presentations
1 Constraints, Triggers and Active Databases Chapter 9.
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
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.
Database Architecture The Relational Database Model.
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)
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
The Relational Model These slides are based on the slides of your text book.
1 Lecture 04 The relational data Model, Relational Constraints 1.
Relational Model Session 6 Course Name: Database System Year : 2012.
1 Introduction to modeling Relational modelling Slides for this part are based on Chapters 11 from Halpin, T. & Morgan, T. 2008, Information Modeling and.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
Relational Data Model. A Brief History of Data Models  1950s file systems, punched cards  1960s hierarchical  IMS  1970s network  CODASYL, IDMS 
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
INTEGRITY. Integrity constraint Integrity constraints are specified on a database schema and are expected to hold on every valid database state of the.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
1 The Relational Model Instructor: Mohamed Eltabakh
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
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.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
1 CS 430 Database Theory Winter 2005 Lecture 7: Designing a Database Logical Level.
The relational model1 The relational model Mathematical basis for relational databases.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Relational Model Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3.
4/20/2018.
RELATION.
Database Design The Relational Model Text Ch5
The Relational Data Model
The Relational Model Relational Data Model
12/7/2018.
The Relational Data Model and Relational Database Constraints
4/8/2019.
5/12/2019.
Copyright © 2004 Pearson Education, Inc.
CS 405G: Introduction to Database Systems
RELATIONAL DATA MODEL - 1
Presentation transcript:

1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model

2 Domains A Domain is a set of atomic values  Atomic: the values are indivisible as far as the relational model is concerned  Easy examples: Numbers Character strings Dates  Questionable example: A set of Character Strings  Allowed by some theoreticians  Not allowed by many RDBMSs  Assumption: Domains come with appropriate operations for each domain

3 Relation Schema Denoted by: R(A 1, A 2, …, A n )  R is the name of the Relation  A 1, A 2, …, A n is the list of attributes of R Attributes are names  Each attribute has an associated Domain: dom(A i )  n is the Degree or Arity of the Relation Example:  PROJECT (PName, PNumber, PLocation, DNum) Domains: Appropriate strings and numbers

4 Tuples Relation or Relation State  Date: Relation Variable  r(R) = {t 1, t 2, …, t m } May use just r if the context is clear A mathematical set  Each t = An (ordered) tuple of values Each v i is either a member of dom(A i ) or the special null value Mathematically  r is a subset of the cartesian product of the dom(A i )

5 Relations The term Relation State is used to emphasize the potential time varying nature of the relation Characteristics  There is no order for the tuples of relation (the t i )  The ordering of values in a tuple is only important to associate each value with the corresponding domain It is possible to define relations as a mapping of attributes to values, thereby removing the order However, in SQL there are cases where the order is important  The null value is provided for representing unknown or not applicable data

6 Relations (Continued) A Relation can be viewed as a set of facts or assertions in a logic programming language  “Closed World” assumption: all true (at the current time) facts are in the database  “Open World” assumption: opposite of “Closed World”  Most database applications make the “closed world” assumption Notation  t[A i ] or t.A i or t[i] can be used to refer an attribute value  t[A u, A v, … A z ] or t.(A u, A v, … A z ) can be used to refer to the corresponding sub-tuple of t

7 Database A Relational Database Schema S is a set of Relations and a set of Integrity Constraints  S = ({R 1, R 2, …, R m }, IC)  Integrity Constraints are a collection of assertions or predicates that should be satisfied by the database A Database State DB is  A set of Relation States DB = {r 1 (R 1 ), r 2 (R 2 ), …, r m (R m )}  which satisfy the Integrity Constraints

8 Example Relational Schema  See Figure 5.5 of Text Book Relational State  See Figure 5.6 of Text Book

9 Constraints Internal  Ones enforced by the DBMS External  Ones true in the users view of the world  Some may be enforced by Application software

10 Types of Internal Constraints Inherent Model Based Constraints  Ones based on relational model, e.g. no repeated values Schema-Based Constraints  Domain Constraints Attributes must be in the corresponding domain  Key Constraints and Constraints on Null Values  Entity Integrity, Referential Integrity, and Foreign Keys  General Constraints and Triggers

11 General Constraints and Triggers Some DBMSs provide mechanisms for General Constraints and Triggers  General constraint: an arbitrary assertion attached to a Table (Relation) or Schema  Trigger: procedural code that is executed when certain kinds of events (e.g. updating the database) occur These can be used to enforce arbitrary constraints Example:  No employee makes more than their supervisor

12 Key Constraints Super Key  For a given relation R, a subset of the attributes {A u, A v, … A z } such that t[A u, A v, … A z ] uniquely determines t (Candidate) Key  A super key which is minimal or irreducible in the sense that no smaller subset of the attributes is also a Super Key Primary and Alternate Keys  Primary Key - some chosen (distinguished) Candidate Key  Alternate Key - any non-primary Candidate Key

13 Entity Integrity  All attributes of a primary key are non-null  Good practice: All attributes of an candidate key are non-null Question: If nulls are allowed how is it a candidate key?

14 Foreign Keys Foreign Key or Referential Integrity Constraint  Given relations R 1 and R 2, a subset FK of the attributes of R 1, FK = {A u, A v, … A z } is a foreign key referencing R 2 which has primary PK if given t 1 a tuple in R 1 either 1. t 1 [FK] is null, or 2. there exists a tuple t 2 in R 2 with t 1 [FK] = t 2 [PK] Notes 1. R 1 and R 2 can be the same relation 2. Circular foreign key dependencies are allowed Example:  See figure 5.7 in Text Book

15 Database Operations and Constraint Violations Three basic kinds of update operations in the relational model:  Insert  Update  Delete What happens if an operation causes a constraint violation Especially violation of a referential integrity constraint

16 Possible Remedies No Action  Don’t do anything, accept the action as is This may cause problems “down the road” Restrict  Refuse the action Cascade  Cascade the change to other tuples to correct violation Set Null and Set Default  Set offending attributes to null or a default value

17 Insert Violations Domain constraint  Insert value not in domain Key constraint  New tuple with same key Entity integrity  Primary key attribute is null Foreign Key  Foreign key refers to tuple that doesn’t exist Generally Restrict (i.e. Reject) such an Insert

18 Delete Violations Foreign Key  Delete primary key referred to by foreign key  Remedies: No Action: Accept operation  May result in subsequent integrity violations Restrict: Reject operation Cascade: delete referring records Set Null or Set Default: Modify referencing keys to some other value

19 Update Violations Domain, Key, Entity  Same as insert - usually Rejected Foreign Key  Modify primary key referred to by foreign key No action, Restrict, Set Null or Set Default: same as insert Cascade: modify referencing keys to new value