Chapter 3-Relational Data Model
Chapter 3-Relational Data Model
Chapter Three: Relational Data Model A number of several commercial products exist in the market
3.1 Introduction which uses relational data models. Examples include oracle,
The relational model was proposed by Dr.Codd in his
MS SQL server, SYBASE, INFORMIX e.t.c. several free open
mathematical paper of 1970s as an attempt to simplify the
source products include MYSQL, PostreSQL.
database structure. The model eliminates the parent/child
Relational data model is the most dominant for developing
structures from database and in return present database as
database applications. Some SQL relational standards include
simple row/column tables of data values.
SQL-89 (SQL1), SQL-92(SQL2) SQL-99 e.t.c
45
Database Systems
3.3.2 Attribute/column/field attributes is usually known as binary, one with three is
It’s a named column of a relation. In relational model, referred to as tertiary and so on
relations are used to hold information about objects to be 3.3.6 Cardinality of a relation
represented in the database. Relations are represented as a It refers to the number of tuples a relation contains. Cardinality
two dimensional table in which rows of the table correspond changes as tuples are deleted and added to a relation. It’s a property
attributes.
3.3.3 Domain
It’s a set of allowable values for one or more attributes. Each
attribute of a relation is defined on a domain. They may be
distinct for each attribute or more attributes maybe defined on
the same domain. For example, if we have an attribute named
gender, its domain values would be male and female
3.3.4 Tuple
3.3 Database Keys
This is a row of a relation. They can appear in any order and Database keys are an integral component of database design
the relation will still convey the same meaning. since theyensure the integrity of the data contained and
3.3.5 Degree of a relation retrieved from the database. Moreover, they ensure each
This refers to the number of attribute a given relation record within a table can be uniquely identified by one or a
contains. A relation with one attribute will have degree one combination of fields within the table as well as help identify
and will be referred to as unary relation, relation with two the relationship between tables.
46
Database Systems
The following section discuss of the database key tuples do not duplicate in a relation. Just like a candidate key,
3.4.1 Super key a primary key must
This refers an attribute/set of attributes that uniquely contain unique values,
identifies a tuple within a given relation. It may contain Never be null a
additional attributes that are not necessary for unique Uniquely identify each record in the table.
identifications. 3.4.4 Foreign key
3.4.2 Candidate Key A foreign key is generally a primary key from one table that
It’s an attribute/set of attributes that has possibility of being appears as a field in another where the first table has a
nominated as primary key. For an attribute to be nominated relationship to the second i.e. if we had a table A with a
as primary key, it has to meet the following primary key X that linked to a table B where X was a field in
It must contain unique values to uniquely tuples in a B, then X would be a foreign key in B.
record
It must not contain null values Let’s consider two tables i.e. student and course table. The
It contains the minimum number of fields to ensure course contains a course_id which uniquely identifies each
uniqueness course hence the primary key of the table course. On the
3.4.3 Primary key hand, the course table contains the course_id which denotes
Once your candidate keys have been identified you can now which course a particular student does. The 2 tables are linked
select one to be your primary key. A primary key refers to a through course_id and as such course_id would be a foreign
candidate key that has been selected to uniquely/chosen to key in the student table.
uniquely identify tuples within a relation. The key ensures
47
Database Systems
3.4.7 Compound Key
It’s a key consisting of more than one field to uniquely
identify a record. Let’s Assume we have an entity named
enrolment, which holds the courses on which a student is
enrolled in a given semesters. A student is allowed to enrol on
more than one course and a course can be enrolled by zero or
many students. We can represent the information as follows
48
Database Systems
which make up the key, are not simple keys in their own This restriction applies to primary key of base relation. The
right. rule states that for every instance of an entity, the value of the
primary key must exist, be unique, and cannot be null.
Let’s assume we decide to uniquely identify all the record Without entity integrity, the primary key could not fulfil its
using two attributes i.e. student number + lastName while we role of uniquely identifying each instance of an entity.
uniquely identify the course using the course number. Since 3.4.2 Referential Integrity
student number and LastName are not each simple keys, they This restriction deals with foreign key and it states that every
have to be combined in order to uniquely identify the student foreign key value must match a primary key value in an
hence they can be referred to as composite key. associated table or the value is wholly null. Referential
integrity ensures that we can correctly navigate between
3.4 Integrity Constraints
As noted earlier in our previous chapter, one component of related entities.
the data model is a set of constraints to ensure data is 3.4.3 General constraints
executed accurately. These are additional rules/restrictions specified by
Integrity is a major component of the relational model since it users/DBA that specify additional constraints that data must
ensures data values in the database are correct and consistent satisfy with respect to a particular enterprise. The DBA can
using entity and referential integrity rules. specify a rule that salary of staff should not be less than 5000,
which the BMS will enforce.
There are three major types of integrity constraints that can be 3.5 Insert and Delete Rules
implemented by a relational Database Management Systems A foreign key creates a hierarchical relationship between two
(RDBMS) i.e. entity, referential and general constraints associated entities. The entity containing the foreign key is
3.4.1 Entity integrity known as child/dependent table while the table containing
49
Database Systems
the primary key from which the foreign key values are instance/primary key value doesn’t exist, the foreign
obtained is known as parent. key in the child is set to previously defined value.
Customized insert rule which allows insertion of a
In order to maintain referential integrity between the parent foreign key value only if that value meets certain
and child as data is inserted or deleted from the database customized validity constraints
certain insert and delete rules must be considered. No Effect insert rule which allows insertion of a
3.5.1 Insert Rules foreign key value without doing a validity check to
Insert rules commonly implemented are: ascertain if a matching primary key value exists or not
Dependent insert rule which allows insertion of a in associated dependent table
foreign key value only if matching parent entity 3.5.2 Delete Rules
instance/primary already exists. The following delete rules can specified while creating a
Automatic insert rule which allows insertion of a database
foreign key value. If matching parent entity Restrict delete rule which allows deletion of parent
instance/primary key value does not exist, it is created. entity instance/primary key value only if there are no
Nullify insert rule which allows insertion of a foreign matching child entity instances.
key value. If a matching parent entity Cascade delete rule which always permits deletion of a
instance/primary does not exist, the foreign key in parent entity instance/primary key value and deletes
Default insert rule which allows insertion of foreign Nullify delete rule which permits deletion of a parent
key value .If a matching parent entity entity instance/primary key value. If there any
50
Database Systems
matching child entity instances exist, their values are Date Format—the format for date values such as
set to null. dd/mm/yy or yy/mm/dd
Default delete rule which allow deletion of parent Range—the range specifies the lower and upper
entity instance/primary key value. If any matching boundaries of the values the attribute may legally have
child entity instances exist, their values are set to a Constraints—are special restrictions on allowable
predefined default value. values.
Customized delete rule which allows a primary key Null support—Indicates whether the attribute can
value to be deleted if it follows a certain validity have null values
constraints are met. Default value (if any)—the value an attribute instance
No Effect delete rules which allows deletion of primary will have if a value is not entered.
key value without doing a validity rule to ascertain if a 3.7 Base relations
matching child entity instance exist or Named relations corresponding to an entity in the conceptual
schema whose tuples are physically implemented.
3.6 Domains
Each attribute/column in the model should be assigned 3.8 Chapter summary
domain information which includes: SQL is based on relational data model which organizes data in
Data Type—Basic data types are integer, decimal, or a database as collection of columns
character. Most databases support variants of these Each table/relation has a unique name that identifies it
plus special data types for date and time. Each table has one or more columns (field/attributes)
Length—this is the number of digits or characters in arranged in a specific left to right order.
the value.
51
Database Systems
Each table has zero or more rows (tuples) each 3.9 Chapter exercise
containing a single data devalue in each column. Rows 3.10 More reading references
1. James, R. Groff & Paul, P. (2006). The complete
can be arranged in any order.
reference SQL (2rd ed.). Oxford, India: Tata McGraw-
All data values in a given column have the same data
Hill publishing Company Limited. [Pp57-67]
type are from a given domain of values called domain
of a column
Tables are related to one another by the data they contain.
Relational data model uses the database keys to model these
relationships among the table.
A primary key is a field or combination of fields that
uniquely each tuple of a table
A foreign key on the other hand is a field or
combination of fields in tables whose values are
primary key value for some other table. A table can
have one or more than one foreign key linking it to one
or more tables.
A primary/foreign key combination usually creates a
parent/child relationship between the tables
themselves
52