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

Week 6 - The Relational Data Model and Relational Database Constraints

Uploaded by

shaik anjum
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)
21 views

Week 6 - The Relational Data Model and Relational Database Constraints

Uploaded by

shaik anjum
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/ 14

CHAPTER 5

The Relational Data Model and


Relational Database Constraints

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 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

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


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- 7
Example – A relation STUDENT

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


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

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


Key Constraints
 If a relation has several candidate keys, one is chosen 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- 10


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

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


Entity Integrity
 Entity Integrity:
 The primary key attributes PK of each relation schema

R in S cannot have null values in any tuple of r(R).


 This is because primary key values are used to identify the
individual tuples.
 t[PK]  null for any tuple t in r(R)
 If PK has several attributes, null is not allowed in any of these
attributes
 .

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


Referential Integrity
 A constraint involving two relations
 The previous constraints involve a single relation.
 Used to specify a relationship among tuples in
two relations:
 The referencing relation and the referenced
relation.

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


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

You might also like