Top Banner

of 15

10 - Relational Model Concepts

Jun 04, 2018

Download

Documents

Fahad Khosa
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/13/2019 10 - Relational Model Concepts

    1/15

    Relational Model

  • 8/13/2019 10 - Relational Model Concepts

    2/15

    Relational Model Constraints

    The state of the whole database will correspond to the statesat a particular point in time. There are generally many restrictconstraints on the actual values in a database state.

    Constraints on databases can generally be divided into threecategories:

    Inherent model-based constraints.

    Constraint that inherit in the data model e.g. a relation cannot his an inherent constraint.

    Schema-based constraints

    Constraint that are expressed in schemas of the data model

    Application-based constraints

    Constraint that does not apply in the schema of the data modelenforced by the application program.

    2

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    3/15

    Relational Integrity Constraints

    Constraints are conditions that must hold onrelation instances. There are three main typeconstraints:

    1. Keyconstraints

    2. Entity integrityconstraints

    3. Referential integrityconstraints

    3

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    4/15

    Key Constraints

    Superkeyof R: A set of attributes SK of R such t

    tuples in any valid relation instance r(R) will havalue for SK. That is, for any distinct tuples t1 ant1[SK] t2[SK].

    Keyof R: A "minimal" superkey; that is, a superkremoval of any attribute from K results in a set othat is not a superkey.

    Example:The CAR relation schema:

    CAR(State, Reg#, SerialNo, Make, Model, Year)

    has two keys Key1 = {State, Reg#}, Key2 = {SerialNo}, whsuperkeys. {SerialNo, Make} is a superkey but not a k

    If a relation hasseveral candidate keys, one isarbitrarily to be the primary key. The primary keare underlined.

    4

  • 8/13/2019 10 - Relational Model Concepts

    5/15

    Key Constraints5

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    6/15

    Entity Integrity

    Relational Database Schema: A set S of relation

    belong to the same database. S is the name of S = {R1, R2, ..., Rn}

    Entity Integrity: The primary key attributes PK of eschema R in S cannot have null values in any tupis because primary key values are used to identiindividual tuples.

    t[PK] null for any tuple t in r(R)

    Note: Other attributes of R may be similarly consdisallow null values, even though they are not mprimary key.

    6

  • 8/13/2019 10 - Relational Model Concepts

    7/15

    Referential Integrity

    A constraint involving two relations (the previou

    involve asingle relation). Used to specify arelationship among tuples in tw

    the referencing relationand the referenced rela

    Tuples in thereferencing relation R1have attribu(called foreign keyattributes) that reference theattributes PK of thereferenced relation R2. A tup

    said to referencea tuple t2in R2if t1[FK] = t2[PK].

    A referential integrity constraint can be displayerelational database schema as a directed arc frR2.

    7

  • 8/13/2019 10 - Relational Model Concepts

    8/15

    Referential IntegrityConstraint

    Statement of the constraint

    The value in the foreign key column (or columns) FK of the the rerelation R1can be either:

    (1) a value of an existing primary key valuecorresponding primary key PK in the referen

    relation R2,, or..(2) a null.

    In case (2), the FK in R1 should not be a part oprimary key.

    8

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    9/15

    9

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    10/15

    Other Types of Constraints

    Semantic Integrity Constraints:

    - based on application semantics and cannot be expressed bythe model

    - E.g., the max. no. of hours per employee for all projects he orshe works on is 56 hrs per week

    - A constraint specification languagemay have to be used toexpress these

    10

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    11/15

    11

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    12/15

    12

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    13/15

    Update Operations on Relations

    INSERT a tuple.

    DELETE a tuple.

    MODIFY a tuple.

    Integrity constraints should not be violated by the

    operations. Several update operations may have to be grou

    together.

    Updates may propagate to cause other updateautomatically. This may be necessary to maintai

    constraints.

    13

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    14/15

    Update Operations on Relations

    In case of integrity violation, several actiotaken:

    Cancel the operation that causes the violatiooption)

    Perform the operation but inform the user of t

    Trigger additional updates so the violation is c(CASCADE option, SET NULL option)

    E.g.Use the ON DELETE CASCADE option to spwhether you want rows deleted in a child tabcorresponding rows are deleted in the parent

    Execute a user-specified error-correction routi

    14

    Database Management Systems

  • 8/13/2019 10 - Relational Model Concepts

    15/15

    In-Class Exercise

    (Taken from Exercise 5.15)Consider the following relations for a database that keepenrollment in courses and the books adopted for each co

    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 schema.

    15

    Database Management Systems