0% found this document useful (0 votes)
5 views

Chapter 3 Bus509

Uploaded by

oldschoolwoman03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Chapter 3 Bus509

Uploaded by

oldschoolwoman03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Topic 3

The Relational Data Model and Relational


Database Constraints

Ahmed Imran Kabir


Adjunct Lecturer
School of Business and Economics
United International University

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe 1-1


Informal Definitions

 Informally, a relation looks like a table of values.

 A relation typically contains a set of rows.

 The data elements in each row represent certain facts


that correspond to a real-world entity or relationship
 In the formal model, rows are called tuples

 Each column has a column header that gives an indication


of the meaning of the data items in that column
 In the formal model, the column header is called an
attribute name (or just attribute)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 2


Example of a Relation

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 3


Informal Definitions
 Key of a Relation:
 Each row has a value of a data item (or set of items)
that uniquely identifies that row in the table
 Called the key
 In the STUDENT table, SSN is the key

 Sometimes row-ids or sequential numbers are


assigned as keys to identify the rows in a table
 Called artificial key or surrogate key

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 4


Formal Definitions - Schema
 The Schema (or description) of a Relation:
 Denoted by R(A1, A2, .....An)
 R is the name of the relation
 The attributes of the relation are A1, A2, ..., An
 Example:
CUSTOMER (Cust-id, Cust-name, Address, Phone#)
 CUSTOMER is the relation name
 Defined over the four attributes: Cust-id, Cust-name,
Address, Phone#
 Each attribute has a domain or a set of valid values.
 For example, the domain of Cust-id is 6 digit numbers.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 5


Formal Definitions - Tuple
 A tuple is an ordered set of values (enclosed in angled
brackets ‘< … >’)
 Each value is derived from an appropriate domain.
 A row in the CUSTOMER relation is a 4-tuple and would
consist of four values, for example:
 <632895, "John Smith", "101 Main St. Atlanta, GA 30332",
"(404) 894-2000">
 This is called a 4-tuple as it has 4 values
 A tuple (row) in the CUSTOMER relation.
 A relation is a set of such tuples (rows)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 6


Formal Definitions - Domain
 A domain has a logical definition:
 Example: “USA_phone_numbers” are the set of 10 digit phone
numbers valid in the U.S.
 A domain also has a data-type or a format defined for it.
 The USA_phone_numbers may have a format: (ddd)ddd-dddd where
each d is a decimal digit.
 Dates have various formats such as year, month, date formatted
as yyyy-mm-dd, or as dd mm,yyyy etc.

 The attribute name designates the role played by a domain in a


relation:
 Used to interpret the meaning of the data elements corresponding

to that attribute
 Example: The domain Date may be used to define two attributes
named “Invoice-date” and “Payment-date” with different meanings

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 7


Definition Summary
Informal Terms Formal Terms
Table Relation
Column Header Attribute
All possible Column Domain
Values
Row Tuple

Table Definition Schema of a Relation


Populated Table State of the Relation
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 8
Example – A relation STUDENT

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 9


Same state as previous Figure (but
with different order of tuples)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 10


CONSTRAINTS
Constraints determine which values are permissible and which
are not in the database.
They are of three main types:
1. Inherent or Implicit Constraints: These are based on the
data model itself. (E.g., relational model does not allow a list as
a value for any attribute)
2. Schema-based or Explicit Constraints: They are
expressed in the schema by using the facilities provided by the
model. (E.g., max. cardinality ratio constraint in the ER model)
3. Application based or semantic constraints: These are
beyond the expressive power of the model and must be
specified and enforced by the application programs.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 11


Relational Integrity Constraints
 Constraints are conditions that must hold on all valid
relation states.
 There are three main types of (explicit schema-based)
constraints that can be expressed in the relational model:
 Key constraints
 Entity integrity constraints
 Referential integrity constraints
 Another schema-based constraint is the domain
constraint
 Every value in a tuple must be from the domain of its
attribute (or it could be null, if allowed for that attribute)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 12


Key Constraints (continued)
 If a relation has several candidate keys, one is chosen
arbitrarily to be the primary key.
 The primary key attributes are underlined.
 Example: Consider the CAR relation schema:
 CAR(State, Reg#, SerialNo, Make, Model, Year)
 We chose SerialNo as the primary key
 The primary key value is used to uniquely identify each
tuple in a relation
 Provides the tuple identity
 Also used to reference the tuple from another tuple
 General rule: Choose as primary key the smallest of the
candidate keys (in terms of size)
 Not always applicable – choice is sometimes subjective

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 13


CAR table with two candidate keys –
LicenseNumber chosen as Primary Key

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 14


COMPANY Database Schema

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 15


Populated database state
 Each relation will have many tuples in its current relation
state
 The relational database state is a union of all the
individual relation states
 Whenever the database is changed, a new state arises
 Basic operations for changing the database:
 INSERT a new tuple in a relation
 DELETE an existing tuple from a relation
 MODIFY an attribute of an existing tuple
 Next slide (Fig. 5.6) shows an example state for the
COMPANY database schema shown in Fig. 5.5.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 16


Populated database state for COMPANY

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 17


Referential Integrity Constraints for COMPANY database

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 18


Update Operations on Relations
 INSERT a tuple.
 DELETE a tuple.
 MODIFY a tuple.
 Integrity constraints should not be violated by the
update operations.
 Several update operations may have to be grouped
together.
 Updates may propagate to cause other updates
automatically. This may be necessary to maintain
integrity constraints.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 19
In-Class Exercise
(Taken from Exercise 5.15)
Consider the following relations for a database that keeps track of student
enrollment in courses and the books adopted for each course:
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 keys for this
schema.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 5- 20

You might also like