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

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

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

CS275 Intro to Databases

CS 377 Database Systems

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

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

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

C Programming

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

Fundamentals of Database Systems

Relational Data Model. Christopher Simpkins

C Programming

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

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

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

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

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

CSE 132A Database Systems Principles

ว ธ การต ดต ง Symantec Endpoint Protection

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

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

Chapter 9: Virtual-Memory Management Dr. Varin Chouvatut. Operating System Concepts 8 th Edition,

Lab 10: Structs and Enumeration

Let s briefly review important EER inheritance concepts

CSC 742 Database Management Systems

ISI Web of Science. SciFinder Scholar. PubMed ส บค นจากฐานข อม ล

A database consists of several tables (relations) AccountNum

CPE 426 Computer Networks. Chapter 5: Text Chapter 23: Support Protocols

I/O. Output. Input. Input ของจาวา จะเป น stream จะอ าน stream ใช คลาส Scanner. standard input. standard output. standard err. command line file.

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

Relational Model and Relational Algebra

ECE 650 Systems Programming & Engineering. Spring 2018

Chapter 4. Introducing Oracle Database XE 11g R2. Oracle Database XE is a great starter database for:

เคร องว ดระยะด วยแสงเลเซอร แบบม อถ อ ย ห อ Leica DISTO ร น D110 (Bluetooth Smart) ประเทศสว ตเซอร แลนด

The Relational Data Model (ALL the Vocabulary)

IS311. Data Structures and Java Collections

Verified by Visa Activation Service For Cardholder Manual. November 2016

CS2300: File Structures and Introduction to Database Systems

SEARCH STRATEGIES KANOKWATT SHIANGJEN COMPUTER SCIENCE SCHOOL OF INFORMATION AND COMMUNICATION TECHNOLOGY UNIVERSITY OF PHAYAO

INPUT Input point Measuring cycle Input type Disconnection detection Input filter

Database Management

Broken Characters Identification for Thai Character Recognition Systems

CS 2451 Database Systems: Relational Data Model

Relational Database Systems Part 01. Karine Reis Ferreira

Lecture 6 Register Transfer Methodology. Pinit Kumhom

The Relational Data Model and Relational Database Constraints

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

IS311 Programming Concepts 2/59. AVA Exception Handling Jการจ ดการส งผ ดปรกต

The CINAHL Databases Searching Tutorial

Chapter 4. The Relational Model

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

กล ม API ท ใช. Programming Graphical User Interface (GUI) Containers and Components 22/05/60

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

DATABASE TECHNOLOGY - 1DL124

Chapter 8: Memory- Management Strategies Dr. Varin Chouvatut

Crystal Report & Crystal Server 2016

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

Introduction to Database Systems. The Relational Data Model

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

Chapter 2 Introduction to Relational Models

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

Chapter 14 Outline. Normalization for Relational Databases: Outline. Chapter 14: Basics of Functional Dependencies and

Lecture Outline. 1. Semantic Web Technologies 2. A Layered Approach 3. Data Integration

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

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

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

JavaScript Framework: AngularJS

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

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

What s Hot & What s New from Microsoft ส มล อน นตธนะสาร Segment Marketing Manager

Chapter 8 INTEGRITY 1

Looking forward to a successful coopertation : TEIN

แผนการสอนว ชา การเข ยนโปรแกรมคอมพ วเตอร 2 (Computer Programming 2) ภาคการศ กษา 1 ป การศ กษา 2559

Chapter 9 Outline. Relational Database Design by ER and EERto-Relational. Mapping Fundamentals of Database Systems

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

Databases. Jörg Endrullis. VU University Amsterdam

DATABASE DESIGN I - 1DL300

The Relational Model of Data (ii)

Relational data model

Database Management System 9

Running Example Tables name location

The Relational Data Model. Data Model

The New Effective Tool for Data Migration from Old PACS (Rogan) to New PACS (Fuji Synapse) with Integrated Thai Patient Names

The Relational Model and Relational Algebra

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

Functional Dependencies CS 1270

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

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

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

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

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

The Relational Model. Week 2

The Relational Model

The Clustering Technique for Thai Handwritten Recognition

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

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Today Topics. Artificial Intelligent??? Artificial Intelligent??? Intelligent Behaviors. Intelligent Behavior (Con t) 20/07/52

Transcription:

Chapter 3 Outline 204321 - Database System 1 Chapter 3 The Relational Data Model and Relational Database Constraints The Relational Data Model and Relational Database Constraints Relational Model Constraints and Relational Database Schemas Update Operations, Transactions, and Dealing with Constraint Violations Adapted for 204321 by Areerat Trongratsameethong Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2 The Relational Data Model and Relational Database Constraints Relational model First commercial implementations available in early 1980s Has been implemented in a large number of commercial system Hierarchical and network models Preceded (มาก อน) the relational model Relational Model Concepts Represents data as a collection of relations Tableof values Row Represents a collection of related data values Fact that typically corresponds to a real-world entity or relationship Tuple Table name and columnnames Interpret the meaning of the values in each row attribute 3 4

Relational Model Concepts (cont d.) Domains, Attributes, Tuples, and Relations DomainD Set of atomic (indivisible) values Atomic Each value indivisible (แบ งแยกไม ได ) Specifying a domain Data type specified for each domain: แต ละ domain ต องม การก าหนดล กษณะของข อม ล 5 6 Domains, Attributes, Tuples, and Relations (cont d.) Relation schema R Denoted by R(A 1,A 2,...,A n ) Made up of a relation name Rand a list of attributes, A 1, A 2,..., A n Relation schema ประกอบด วย ช อ relation R และ attributes A 1,A 2,..., A n ของ R แต ละ Relation อย ในร ป R(A 1,A 2,...,A n ) Attribute A i Name of a role played by some domain Din the relation schema R Degree(or arity) of a relation Number of attributes nof its relation schema Domains, Attributes, Tuples, and Relations (cont d.) Relation (or relation state): Relation State ค อสถานะของ ข อม ลใน Relation ณ เวลาใดเวลาหน ง ซ งแทนด วย set ของ tuple (หร อ record) อย ในร ปแบบ r = {t 1,t 2,..., t m } Set of n-tuplesr = {t 1,t 2,..., t m } Each n-tuple t Ordered list of nvalues t =<v 1, v 2,..., v n > Each value v i, 1 i n, is an element of dom(a i ) or is a special NULL value 7 8

Domains, Attributes, Tuples, and Relations (cont d.) Characteristics of Relations (cont d.) 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 9 Characteristics of Relations (cont d.) Values and NULLs in tuples Each value in a tuple is atomic Flat relational model Composite and multivalued attributes not allowed First normal form assumption Multivalued attributes Must be represented by separate relations Composite attributes Represented only by simple component attributesin basic relational model Characteristics of Relations (cont d.) NULL values Represent the values of attributes that may be unknown or may not applyto a tuple Meanings for NULL values Value unknown Value exists but is not available(บอกไม ได หร อ ณ ขณะน (นย งไม ทราบ) Attribute does not apply to this tuple (also known as value undefined) ไม ได ก าหนด 11 12

Characteristics of Relations (cont d.) Interpretation (meaning) of a relation Assertion Each tuple in the relation is a factor a particular instance of the assertion Predicate Values in each tuple interpreted as values that satisfy predicate (state) Relational Model Notation Relation schema Rof degree n (n attributes) Denoted by R(A 1,A 2,..., A n ) Uppercase letters Q,R,S Denote relation names Lowercase letters q,r,s Denote relation states (เช น r = {t 1,t 2,..., t m }) Letters t,u,v Denote tuples (หร อ record หร อ row) 13 14 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 (A ค อ attribute ของ R) Relational Model Notation n-tuple t in a relation r(r) Denoted by 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 tfor attribute A i :t[a i ] and t.a i หมายถ ง ค าท อย ใน attribute A i ของ tuple t 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 15 16

Relational Model Constraints Constraints Restrictions on the actual values in a database state: ก าหนดข อบ งค บของข อม ลท จะเข าไปอย ในฐานข อม ล Derived from the rules in the miniworldthat the database represents: ข อบ งค บได มาจากความเป นจร งของข อม ล เช น อาย ของส งม ช ว ตม ค า > 0 Inherent model-based constraints or implicit constraints Inherent in the data model: ได ร บส บทอดมาจากข อบ งค บของ แต ละ data model 17 Relational Model Constraints (cont d.) Schema-based constraints or explicit constraints Can be directly expressed in schemasof the data model: กฎข อบ งค บท สามารถก าหนดโดยตรงใน data model หร อ database schema Application-based or semantic constraints or business rules Cannot be directly expressed in schemas Expressed and enforced by application program กฎข อบ งค บท ไม สามารถก าหนดโดยตรงใน data model หร อ database schema จะถ กก าหนดไว ใน application program แทน เช น ห ามเบ ก OT เก น 4 ช วโมงในว นธรรมดา 18 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 Key Constraints and Constraints on NULL Values No two tuplescan have the same combination of values for all their attributes. Superkey No two distinct tuplesin any state rof Rcan have the same value for SK Key Superkeyof R Removing any attribute Afrom Kleaves a set of attributes Kthat is not a superkeyof Rany more 19 20

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 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 21 22 Key Constraints and Constraints on NULL Values (cont d.) 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 and such that the r i relation states satisfy integrity constraints specified in IC 24

Relational Databases and Relational Database Schemas (cont d.) Invalid state Does not obey all the integrity constraints Valid state Satisfies all the constraints in the defined set of integrity constraints IC Integrity, Referential Integrity, and Foreign Keys Entity integrity constraint No primary key value can be NULL Referential integrity constraint Specified between two relations Maintains consistency among tuples in two relations 25 26 Integrity, Referential Integrity, and Foreign Keys (cont d.) Foreign key rules: The attributes in FK have the same domain(s) as the primary key attributes PK 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 tuplet 2 in the current state r 2 (R 2 )or is NULL Integrity, Referential Integrity, and Foreign Keys (cont d.) Diagrammatically display referential integrity constraints Directed arc from each foreign key to the relation it references All integrity constraints should be specified on relational database schema PK Student N 1 isin StudentID (PK) FacultyID (FK): - ต องม รห ส FacultyID อย ใน Faculty - หร อม รห ส FacultyID ใน Student เป น NULL Faculty FacultyID (PK): PK ห ามเป น NULL 27 FK 28

Other Types of Constraints Semantic integrity constraints May have to be specified and enforced on a relational database Use triggers: เม อม เหต การณ ท ท าให ข อม ลม การInsert Update Delete เก ดข (นในฐานข อม ล จะกระต นให DBMS ท าอะไรบางอย าง assertions: ค าส งท ใช ในการตรวจสอบความถ กต องของข อม ล e.g. check to make sure that total loan never exceeds the total amount in the bank More common to check for these types of constraints within the application programs 29 Other Types of Constraints (cont d.) Functional dependency constraint Establishes a functional relationship among two sets of attributes Xand Y Value of Xdetermines a unique value of Y จะได เร ยนใน FD และ Normalization State constraints Define the constraints that a valid state of the database must satisfy Transition constraints Define to deal with state changes in the database 30 Update Operations, Transactions, and Dealing with Constraint Violations Operations of the relational model can be categorized into retrievals and updates Basic operations that change the states of relations in the database: Insert Delete Update (or Modify) 31 32

33 34 The Insert Operation Provides a list of attribute values for a new tuple tthat is to be inserted into a relation R Can violate any of the four types of constraints If an insertion violates one or more constraints Default option is to reject the insertion The Delete Operation Can violate (ข ดแย ง)only referential integrity 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 35 36

The Update Operation Necessary to specify a condition on attributes of relation Select the tuple (or tuples) to be modified If attribute 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 Not Null Transaction The Transaction Concept Executing program Includes some database operations Must leave the database in a valid or consistent state Online transaction processing (OLTP) systems Execute transactions at rates that reach several hundred per second Referential Integrity Constraint 37 38 Summary Characteristics differentiate relations from ordinary tables or files Classify database constraints into: Inherent model-based constraints, explicit schema-based constraints, and application-based constraints Modification operations on the relational model: Insert, Delete, and Update 39