Relational Data Model
1
Chapter 2 - Objectives
 Terminology of relational model.
 How tables are used to represent data.
 Properties of database relations.
 How to identify PK, AK, and FKs.
 Meaning of entity integrity and
referential integrity.
2
© Pearson Education Limited 1995, 2005
Relational Model
Terminology
 A relation is a table with columns and
rows.
 Only applies to logical structure of the
database, not the physical structure.
 Attribute is a named column of a relation.
 Domain is the set of allowable values for
one or more attributes.
3
© Pearson Education Limited 1995, 2005
Relational Model
Terminology
 Tuple is a row of a relation.
 Degree is the number of attributes in a
relation.
 Cardinality is the number of tuples in a
relation.
 Relational Database is a collection of
normalized relations with distinct relation
names.
4
© Pearson Education Limited 1995, 2005
Instances of Branch and
Staff Relations
5
© Pearson Education Limited 1995, 2005
Examples of Attribute
Domains
6
© Pearson Education Limited 1995, 2005
Alternative Terminology for
Relational Model
7
© Pearson Education Limited 1995, 2005
Database Relations
 Relation schema
 Named relation defined by a set of attribute
and domain name pairs.
 Relational database schema
 Set of relation schemas, each with a
distinct name.
8
© Pearson Education Limited 1995, 2005
9
Terminology
Name Price Category Manufacturer
gizmo $19.99 gadgets GizmoWorks
Power gizmo $29.99 gadgets GizmoWorks
SingleTouch $149.99 photography Canon
MultiTouch $203.99 household Hitachi
Tuples or rows or records
Attribute names
Table name or relation name
Products:
Schemas
Relational Schema:
 Relation name plus attribute names
 E.g. Product(Name, Price, Category,
Manufacturer)
 In practice we add the domain for each attribute
Database Schema
 Set of relational schemas
 E.g. Product(Name, Price, Category,
Manufacturer),
Company(Name, Address, Phone),
. . . . . . .
10
Example
11
Name Price Category Manufacturer
gizmo $19.99 gadgets GizmoWorks
Power gizmo $29.99 gadgets GizmoWorks
SingleTouch $149.99 photography Canon
MultiTouch $203.99 household Hitachi
Relational schema:Product(Name, Price, Category, Manufacturer)
Instance:
Properties of Relations
 Relation name is distinct from all other
relation names in relational schema.
 Each cell of relation contains exactly
one atomic (single) value.
 Each attribute has a distinct name.
 Values of an attribute are all from the
same domain.
12
© Pearson Education Limited 1995, 2005
Properties of Relations
 Each tuple is distinct; there are no
duplicate tuples.
 Order of attributes has no significance.
 Order of tuples has no significance,
theoretically.
13
© Pearson Education Limited 1995, 2005
Relational Keys
 Candidate Key
 A set of one or more attributes(minimal) that can
uniquely indentify a row/tuple in a given table.
 Primary Key
 Candidate key selected to identify row/tuple
uniquely within relation.
 Alternate Keys
 Candidate keys that are not selected to be primary
key.
 Foreign Key
 An attribute (or combination of attributes) in one
table whose values must match the primary key in
another table.
14
© Pearson Education Limited 1995, 2005
Choosing A Primary Key
 Give preference to numeric column(s)
 Give preference to single attribute
 Give preference to minimal composite attribute
15
© Pearson Education Limited 1995, 2005
Choosing Foreign Keys
 A Foreign key is a set of attribute(s) whose
values are required to match values of a column
in the same or another table.
16
© Pearson Education Limited 1995, 2005
Integrity Constraints
 Null
 Represents value for an attribute that is
currently unknown or not applicable for
tuple.
 Deals with incomplete or exceptional data.
 Represents the absence of a value and is
not the same as zero or spaces, which are
values.
17
© Pearson Education Limited 1995, 2005
Integrity Constraints
 Entity Integrity
 In a base relation, no attribute of a primary
key can be null.
 Referential Integrity
 If foreign key exists in a relation, either
foreign key value must match a candidate
key value of some tuple in its home
relation or foreign key value must be
totally null.
18
© Pearson Education Limited 1995, 2005
Integrity Constraints
 General Constraints
 Additional rules specified by users or
database administrators that define or
constrain some aspect of the enterprise.
19
© Pearson Education Limited 1995, 2005
Revision:
20
- Determine the Relational Data Model characterisics
(relation name, attribute, tuple, degree, cardinality,
primary key, foreign key and relation scheme) in the
given relation.
21

Note Database Chapter2-Part 1.pdf and presentation

  • 1.
  • 2.
    Chapter 2 -Objectives  Terminology of relational model.  How tables are used to represent data.  Properties of database relations.  How to identify PK, AK, and FKs.  Meaning of entity integrity and referential integrity. 2 © Pearson Education Limited 1995, 2005
  • 3.
    Relational Model Terminology  Arelation is a table with columns and rows.  Only applies to logical structure of the database, not the physical structure.  Attribute is a named column of a relation.  Domain is the set of allowable values for one or more attributes. 3 © Pearson Education Limited 1995, 2005
  • 4.
    Relational Model Terminology  Tupleis a row of a relation.  Degree is the number of attributes in a relation.  Cardinality is the number of tuples in a relation.  Relational Database is a collection of normalized relations with distinct relation names. 4 © Pearson Education Limited 1995, 2005
  • 5.
    Instances of Branchand Staff Relations 5 © Pearson Education Limited 1995, 2005
  • 6.
    Examples of Attribute Domains 6 ©Pearson Education Limited 1995, 2005
  • 7.
    Alternative Terminology for RelationalModel 7 © Pearson Education Limited 1995, 2005
  • 8.
    Database Relations  Relationschema  Named relation defined by a set of attribute and domain name pairs.  Relational database schema  Set of relation schemas, each with a distinct name. 8 © Pearson Education Limited 1995, 2005
  • 9.
    9 Terminology Name Price CategoryManufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $149.99 photography Canon MultiTouch $203.99 household Hitachi Tuples or rows or records Attribute names Table name or relation name Products:
  • 10.
    Schemas Relational Schema:  Relationname plus attribute names  E.g. Product(Name, Price, Category, Manufacturer)  In practice we add the domain for each attribute Database Schema  Set of relational schemas  E.g. Product(Name, Price, Category, Manufacturer), Company(Name, Address, Phone), . . . . . . . 10
  • 11.
    Example 11 Name Price CategoryManufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $149.99 photography Canon MultiTouch $203.99 household Hitachi Relational schema:Product(Name, Price, Category, Manufacturer) Instance:
  • 12.
    Properties of Relations Relation name is distinct from all other relation names in relational schema.  Each cell of relation contains exactly one atomic (single) value.  Each attribute has a distinct name.  Values of an attribute are all from the same domain. 12 © Pearson Education Limited 1995, 2005
  • 13.
    Properties of Relations Each tuple is distinct; there are no duplicate tuples.  Order of attributes has no significance.  Order of tuples has no significance, theoretically. 13 © Pearson Education Limited 1995, 2005
  • 14.
    Relational Keys  CandidateKey  A set of one or more attributes(minimal) that can uniquely indentify a row/tuple in a given table.  Primary Key  Candidate key selected to identify row/tuple uniquely within relation.  Alternate Keys  Candidate keys that are not selected to be primary key.  Foreign Key  An attribute (or combination of attributes) in one table whose values must match the primary key in another table. 14 © Pearson Education Limited 1995, 2005
  • 15.
    Choosing A PrimaryKey  Give preference to numeric column(s)  Give preference to single attribute  Give preference to minimal composite attribute 15 © Pearson Education Limited 1995, 2005
  • 16.
    Choosing Foreign Keys A Foreign key is a set of attribute(s) whose values are required to match values of a column in the same or another table. 16 © Pearson Education Limited 1995, 2005
  • 17.
    Integrity Constraints  Null Represents value for an attribute that is currently unknown or not applicable for tuple.  Deals with incomplete or exceptional data.  Represents the absence of a value and is not the same as zero or spaces, which are values. 17 © Pearson Education Limited 1995, 2005
  • 18.
    Integrity Constraints  EntityIntegrity  In a base relation, no attribute of a primary key can be null.  Referential Integrity  If foreign key exists in a relation, either foreign key value must match a candidate key value of some tuple in its home relation or foreign key value must be totally null. 18 © Pearson Education Limited 1995, 2005
  • 19.
    Integrity Constraints  GeneralConstraints  Additional rules specified by users or database administrators that define or constrain some aspect of the enterprise. 19 © Pearson Education Limited 1995, 2005
  • 20.
    Revision: 20 - Determine theRelational Data Model characterisics (relation name, attribute, tuple, degree, cardinality, primary key, foreign key and relation scheme) in the given relation.
  • 21.