Data Model
Data Models
 A collection of conceptual tools for
describing
 data
 data relationships
 data semantics
 data constraints
 Relational model
 Entity-Relationship model
 Other models:
 object-oriented model
 semi-structured data models
 Older models: network model and hierarchical model
Relational Data Structure
 RelationRelation
 A table with columns and rows
 AttributeAttribute
 Named column of a relation
 DomainDomain
 Set of allowable values for one or more attributes
 TupleTuple
 A row in a relation
 DegreeDegree (of a relation)
 The number of attributes it contains
 CardinalityCardinality (of a relation)
 The number of tuples it contains
3
Alternate Terminology
4
Formal Terms Alternative 1 Alternative 2
Relation Table File
Tuple Row Record
Attribute Column Field
Mathematical Relations
D1 = {2, 4} and D2 = {1, 3, 5}
D1xD2 = {(2,1), (2,3), (2,5), (4,1), (4,3), (4,5)}
• Any subset of this Cartesian Product is a Relation
5
Database Relations
 Relation SchemaRelation Schema
 A named relation defined by a set of attributes and
domain name pairs
 Relational Database SchemaRelational Database Schema
 A set of relation schemas each with a distinct name
6
Properties of Relations
 Has a name that is different from all other
relation names
 Each cell of a relation contains exactly one
atomic value (no arrays)
 Each attribute has a distinct name
 The values of an attribute are all from the same
domain
 Each tuple is distinct (no duplicate rows)
 The order of attributes has no significance
7
Relational Keys
 SuperkeySuperkey
 An attribute or a set of attributes that uniquely identifies a tuple
 Candidate KeyCandidate Key
 A superkey such that no proper subset is a superkey
 Primary KeyPrimary Key
 The candidate key that is selected to identify the tuples uniquely
 Foreign KeyForeign Key
 An attribute or a set of attributes within one relation that
matches the candidate key of some relation
8
Representing Relational
Database Schemas
Branch(branchNo, street, city, postCode)
Staff(staffNo, fName, lName, position, gender, DOB,
salary, branchNo)
PropertyForRent(propertyNo, street, city, postCode,
type, rooms, rent, ownerNo, staffNo, branchNo)
…
9
Relational Integrity
• Constraints placed on database in order to ensure
that the data is correct.
• For example, domain constraints, entity integrity
rules, referential integrity rules and other rules
(enterprise constraints)
10
Relational Integrity
 Entity IntegrityEntity Integrity
 In a relation no attribute of a primary key can be null.
 Referential IntegrityReferential Integrity
 If a foreign key exists in a relation, either the foreign
key value must match a candidate key value of some
tuple in its home/parent relation or the foreign key
must be wholly null.
11

Data model

  • 1.
  • 2.
    Data Models  Acollection of conceptual tools for describing  data  data relationships  data semantics  data constraints  Relational model  Entity-Relationship model  Other models:  object-oriented model  semi-structured data models  Older models: network model and hierarchical model
  • 3.
    Relational Data Structure RelationRelation  A table with columns and rows  AttributeAttribute  Named column of a relation  DomainDomain  Set of allowable values for one or more attributes  TupleTuple  A row in a relation  DegreeDegree (of a relation)  The number of attributes it contains  CardinalityCardinality (of a relation)  The number of tuples it contains 3
  • 4.
    Alternate Terminology 4 Formal TermsAlternative 1 Alternative 2 Relation Table File Tuple Row Record Attribute Column Field
  • 5.
    Mathematical Relations D1 ={2, 4} and D2 = {1, 3, 5} D1xD2 = {(2,1), (2,3), (2,5), (4,1), (4,3), (4,5)} • Any subset of this Cartesian Product is a Relation 5
  • 6.
    Database Relations  RelationSchemaRelation Schema  A named relation defined by a set of attributes and domain name pairs  Relational Database SchemaRelational Database Schema  A set of relation schemas each with a distinct name 6
  • 7.
    Properties of Relations Has a name that is different from all other relation names  Each cell of a relation contains exactly one atomic value (no arrays)  Each attribute has a distinct name  The values of an attribute are all from the same domain  Each tuple is distinct (no duplicate rows)  The order of attributes has no significance 7
  • 8.
    Relational Keys  SuperkeySuperkey An attribute or a set of attributes that uniquely identifies a tuple  Candidate KeyCandidate Key  A superkey such that no proper subset is a superkey  Primary KeyPrimary Key  The candidate key that is selected to identify the tuples uniquely  Foreign KeyForeign Key  An attribute or a set of attributes within one relation that matches the candidate key of some relation 8
  • 9.
    Representing Relational Database Schemas Branch(branchNo,street, city, postCode) Staff(staffNo, fName, lName, position, gender, DOB, salary, branchNo) PropertyForRent(propertyNo, street, city, postCode, type, rooms, rent, ownerNo, staffNo, branchNo) … 9
  • 10.
    Relational Integrity • Constraintsplaced on database in order to ensure that the data is correct. • For example, domain constraints, entity integrity rules, referential integrity rules and other rules (enterprise constraints) 10
  • 11.
    Relational Integrity  EntityIntegrityEntity Integrity  In a relation no attribute of a primary key can be null.  Referential IntegrityReferential Integrity  If a foreign key exists in a relation, either the foreign key value must match a candidate key value of some tuple in its home/parent relation or the foreign key must be wholly null. 11