Chapter 3 Outline Relational Model Concepts

Chapter 3 Outline Relational Model Concepts

Chapter 3 Outline 204320 - Database Management • The Relational Data Model and Relational Database Constraints • Relational Model Constraints Chapter 3 and Relational Database Schemas The Relational Data Model and Relational • Update Operations, Transactions, Database Constraints and Dealing with Constraint Violations Adapted for 204320 by Areerat Trongratsameethong 2 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Relational Data Model and Relational Model Concepts Relational Database Constraints • Relational model • Represents data as a collection of relations – First commercial implementations available in • Table of values early 1980s – Row – Has been implemented in a large number of • Represents a collection of related data values commercial system • Fact that typically corresponds to a real-world entity or relationship • Hierarchical and network models • Tuple – Preceded ( มาก่อน ) the relational model – Table name and column names • Interpret the meaning of the values in each row attribute 3 4 Domains, Attributes, Tuples, and Relational Model Concepts (cont’d.) Relations • Domain D – 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 Domains, Attributes, Tuples, and Relations (cont’d.) Relations (cont’d.) • Relation schema R • Relation (or relation state ): Relation State คือสถานะของ – Denoted by R(A1, A2, ..., An) ข้อมูลใน Relation ณ เวลาใดเวลาหนึง ซึงแทนด้วย set ของ tuple ( หรือ – Made up of a relation name R and a list of attributes, A1, record) อยู่ในรูปแบบ r = {t1, t2, ..., tm} A2, ..., A n – Relation schema ประกอบด้วย ชือ relation R และ attributes A , A , 1 2 – Set of n-tuples r = {t1, t2, ..., tm} ..., A n ของ R – Each n-tuple t – แต่ละ Relation อยู่ในรูป R(A1, A2, ..., An) • Attribute Ai • Ordered list of n values t =<v 1, v2, ..., vn> – Name of a role played by some domain D in the relation • Each value vi, 1 ≤ i ≤ n, is an element of dom( Ai) or is a schema R special NULL value • Degree (or arity ) of a relation – Number of attributes n of its relation schema 7 8 Domains, Attributes, Tuples, and Characteristics of Relations (cont’d.) 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.) Characteristics of Relations (cont’d.) • Values and NULLs in tuples • NULL values – Each value in a tuple is atomic – Represent the values of attributes that may be – Flat relational model unknown or may not apply to a tuple • Composite and multivalued attributes not allowed – Meanings for NULL values • First normal form assumption • Value unknown Multivalued attributes – • Value exists but is not available (บอกไม่ได้ หรือ ณ ขณะนั(นยังไม่ทราบ ) • Must be represented by separate relations • Attribute does not apply to this tuple (also known as value – Composite attributes undefined) ไม่ได้กาหนดํ • Represented only by simple component attributes in basic relational model 11 12 Characteristics of Relations (cont’d.) Relational Model Notation • Interpretation (meaning) of a relation • Relation schema R of degree n (n attributes) – Assertion – Denoted by R(A1, A2, ..., An) • Each tuple in the relation is a fact or a particular • Uppercase letters Q, R, S instance of the assertion – Denote relation names – Predicate • Values in each tuple interpreted as values that satisfy • Lowercase letters q, r, s predicate (state) – Denote relation states ( เช่น r = {t1, t2, ..., tm}) • Letters t, u, v – Denote tuples ( หรือ record หรือ row) 13 14 Relational Model Notation Relational Model Notation • n-tuple t in a relation r(R) • Name of a relation schema: STUDENT – Denoted by t = <v 1, v2, ..., vn> – Indicates the current set of tuples in that relation – vi is the value corresponding to attribute Ai • Notation: STUDENT(Name, Ssn, ...) • Component values of tuples: – Refers only to relation schema – t[Ai] and t.A i refer to the value vi in t for attribute Ai • Attribute A can be qualified with the relation :t[Ai] and t.A i หมายถึง ค่าทีอยู่ใน attribute Ai ของ tuple t name R to which it belongs – t[Au, Aw, ..., Az] and t. (Au, Aw, ..., Az) refer to the คือ ของ – Using the dot notation R.A (A attribute R) subtuple of values <v u, vw, ..., vz> from t corresponding to the attributes specified in the list 15 16 Relational Model Constraints Relational Model Constraints (cont’d.) • Constraints • Schema-based constraints or explicit – Restrictions on the actual values in a database constraints state: กําหนดข้อบังคับของข้อมูลทีจะเข้าไปอยู่ในฐานข้อมูล – Can be directly expressed in schemas of the data – Derived from the rules in the miniworld that the model: กฎข้อบังคับทีสามารถกําหนดโดยตรงใน data model หรือ database represents: ข้อบังคับได้มาจากความเป็นจริงของข้อมูล database schema เช่น อายุของสิงมีชีวิตมีค่า > 0 • Application-based or semantic constraints or • Inherent model-based constraints or implicit business rules constraints – Cannot be directly expressed in schemas – Inherent in the data model: ได้รับสืบทอดมาจากข้อบังคับของ – Expressed and enforced by application program แต่ละ data model กฎข้อบังคับทีไม่สามารถกําหนดโดยตรงใน data model หรือ database schema จะถูกกําหนดไว้ใน application program แทน เช่น ห้ามเบิก OT เกิน 0 ชัวโมงในวันธรรมดา 17 18 Key Constraints and Constraints on Domain Constraints NULL Values • Typically include: • No two tuples can have the same combination – Numeric data types for integers and real numbers of values for all their attributes. – Characters • Superkey – Booleans – No two distinct tuples in any state r of R can have – Fixed-length strings the same value for SK – Variable-length strings • Key Date, time, timestamp – – Superkey of R Money – – Removing any attribute A from K leaves a set of – Other special data types attributes K that is not a superkey of R any more 19 20 Key Constraints and Constraints on Key Constraints and Constraints on NULL Values (cont’d.) NULL Values (cont’d.) • Key satisfies two properties: • Candidate key – Two distinct tuples in any state of relation cannot – Relation schema may have more than one key have identical values for (all) attributes in key • Primary key of the relation – Minimal superkey – Designated among candidate keys • Cannot remove any attributes and still have uniqueness constraint in above condition hold – Underline attribute • Other candidate keys are designated as unique keys 21 22 Key Constraints and Constraints on Relational Databases and Relational NULL Values (cont’d.) Database Schemas • Relational database schema S – Set of relation schemas S = {R1, R2, ..., Rm} – Set of Integrity Constraints (IC) • Relational database state – Set of relation states DB = {r1, r2, ..., rm} – Each ri is a state of Ri and such that the ri relation states satisfy integrity constraints specified in IC 24 Integrity, Referential Integrity, Relational Databases and Relational and Foreign Keys Database Schemas (cont’d.) • Entity integrity constraint • Invalid state – No primary key value can be NULL – Does not obey all the integrity constraints • Referential integrity constraint • Valid state – Specified between two relations – Satisfies all the constraints in the defined set of – Maintains consistency among tuples in two integrity constraints IC relations 25 26 Integrity, Referential Integrity, Integrity, Referential Integrity, and Foreign Keys (cont’d.) and Foreign Keys (cont’d.) • Foreign key rules: • Diagrammatically display referential integrity constraints – The attributes in FK have the same domain(s) as the primary key attributes PK – Directed arc from each foreign key to the relation it references – Value of FK in a tuple t1 of the current state r1(R 1) either occurs as a value of PK for some tuple t2 in • All integrity constraints should be specified on the current state r2(R 2) or is NULL relational database schema PK N 1 Student isIn Faculty FK StudentID (PK) FacultyID (PK): PK ห้ามเป็น NULL FacultyID (FK): - ต้องมีรหัส FacultyID อยู่ใน Faculty - หรือมีรหัส FacultyID ใน Student เป็น NULL 27 28 Other Types of Constraints Other Types of Constraints (cont’d.) • Semantic integrity constraints • Functional dependency constraint – May have to be specified and enforced on a – Establishes a functional relationship among two sets of attributes X and Y relational database – Value of X determines a unique value of Y – Use triggers: Insert Update เมือมีเหตุการณ์ทีทําให้ข้อมูลมีการ จะได้เรียนใน FD และ Normalization Delete เกิดขึ(นในฐานข้อมูล จะกระตุ้นให้ DBMS ทําอะไรบางอย่าง • State constraints – assertions: คําสังทีใช้ในการตรวจสอบความถูกต้องของข้อมูล – Define the constraints that a valid state of the e.g. check to make sure that total loan never exceeds the database must satisfy total amount in the bank • Transition constraints – More common to check for these types of – Define to deal with state changes in the database constraints within the application programs 29 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 The Delete Operation • Can violate (ขัดแย้ง ) only referential integrity • Provides a list

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us