You are on page 1of 21

RELATIONAL MODEL

LECTURE 3
Relational database model
The Relational Database Model is the most common model in industry today.  A
relational database is based on the relational model developed by E.F. Codd. A
relational database allows the definition of data structures, storage and retrieval
operations and integrity constraints.
In such a database the data and relations between them are organized into tables. A
table is a collection of records. The contents of a table can be permanently saved for
future use. 
Relational database model
The main highlights of this model are −
■ Data is stored in tables called relations.
■ Relations can be normalized.
■ Each row in a relation contains a unique value.
■ Each column in a relation contains values from a same domain.
Relational database model
Key definitions
■ Entity:-In relation to a database, an entity is a single person, place, or thing about
which data can be stored.
■ Field:-Records are composed of fields, each of which contains one item of
information. A set of records constitutes a file. For example, a personnel file might
contain records that have three fields: a name field, an address field, and a phone
number field.
■ Tuples:-In the context of databases, a tuple is one record (one row).
■ Attribute:-an attribute is a characteristic of an entity. It also may refer to a
database field. Attributes describe the instances in the row of a database
Relational database model cont’d

In DBMS terms a:
■ - Row is Tuple
■ - Column is an Attribute
■ - Table is a Relation
■ - Primary Key (PK) is just a Key
■ - Foreign Key (FK) is a Referential integrity.
Illustration
Logical view
■ The logical view is used to make the users life easier. In a database there is
only one physical view, but there can be multiple ways a user can view each
item, using their own logic that best suits them.
■ The logical view is unique to any one user; each user can decide what they
want to view and how they want to view items on a database.
■ Not only can each individual chose what logical view they would like, but also
they can set that view up as the default. It also allows people to understand
the layout of how the database works, such as the architecture. This helps
users understand the functions and workflows.
Why would a person want to use the
Logical View?
■ Each individual usually has a specific task and differentiates from the next user in a
business, but all employees are working off the same database. All users do not
need to view all areas of the database, only the areas that pertain to their job. This
eliminates the extra information that the specific user will not need. The user will be
able to have a tree like structure or diagram that has a list of all items on the data
base, this also allows the user to see what they can access, but they have the ability
to choose items custom to their needs.

For example:
■  A bookkeeping firm will keep Accounts Receivable Records and Accounts Payable
Records. The business keeps the checks and balance system in place they will have
one employee for the Accounts Receivables (AR) and another employee for the
Accounts Payable (AP). The accounts receivable clerk does not need to see the
checks that are being cut by the accounts payables clerk because it does not
pertain to the accounts receivable clerks’ job.
Why would a person want to use the
Logical View? Cont’d
■ The accounts receivable clerk will set their logical view to show the
Customer Number and maybe the customers balance due. This helps the
accounts receivable clerk view only what he/she needs and makes the
database less complicated. The accounts payables clerk does not need to
view which customers owe and what their balances due are. The accounts
payables clerk only needs to know the bank balance and the invoices that
need to be paid. So the accounts payables clerk at this time will set their
logical view to only view the tables they need.
■ The Logical view will improve a company’s procedures by allowing users to
only access the tables or information that they need to. When in employee is
doing date entry such as accounts receivables it is very repetitive and the
employee does not need any more distractions. By simplifying the data that
the employee is looking at will eliminates minor errors that can actually cause
headaches to the other employees.
Illustration of a logical view
DATABASE key
Keys are, as their name suggests, a key part of a relational database and a vital
part of the structure of a table. They ensure each record within a table can be
uniquely identified by one or a combination of fields within the table. They help
enforce integrity and help identify the relationship between tables. There are
three main types of keys, candidate keys, primary keys and foreign keys among
others.
■ Super key
A super key is a group of single or multiple keys which identifies rows in a table.
Sn,email,Sid, sid+email, sid+sn, sid+email+sn

Sn-serial number
Sid- student id
DATABASE key

■ Candidate Key
A candidate key is a single field or the least combination of fields that uniquely
identifies each record in the table. The least combination of fields distinguishes
a candidate key from a super key. Every table must have at least one candidate
key but at the same time can have several.
Sn, email, sid, sid+email, sid+sn
■ Primary Key
A primary key is a candidate key that is most appropriate to be the main reference key for the
table. As its name suggests, it is the primary key of reference for the table and is used
throughout the database to help establish relationships with other tables. As with any
candidate key the primary key must contain unique values, must never be null and uniquely
identify each record in the table.
In the table below we have selected the candidate key student_id to be our most appropriate
primary key

■ Primary keys are mandatory for every table each record must have a value for its primary
key. When choosing a primary key from the pool of candidate keys always choose a single
simple key over a composite key.
■ Foreign Key
A foreign key is generally a primary key from one table that appears as a field in
another where the first table has a relationship to the second. In other words, if we
had a table A with a primary key X that linked to a table B where X was a field in B,
then X would be a foreign key in B.
An example might be a student table that contains the course_id the student is
attending. Another table lists the courses on offer with course_id being the primary
key. The 2 tables are linked through course_id and as such course_id would be a
foreign key in the student table.
■ Secondary Key or Alternative Key
A table may have one or more choices for the primary key. Collectively these are
known as candidate keys as discuss earlier. One is selected as the primary key.
Those not selected are known as secondary keys or alternative keys.

❑ composite key
A composite key, in the context of relational databases, is a combination of two
or more columns in a table that can be used to uniquely identify each row in the
table. Uniqueness is only guaranteed when the columns are combined; when
taken individually the columns do not guarantee uniqueness.
All super keys with more than one attribute are composite
Sid+email, sn+sid
■ Surrogate
An artificial key which aims to uniquely identify each record is called a surrogate
key. These kind of key are unique because they are created when you don't have
any natural primary key.
If a table has no attribute that can not uniquely identify rows then we create a
surrogate key like that has no impact on the table watsover
Integrity rules
Integrity rule 1: Entity integrity
■ It says that no component of a primary key may be null.
■ Every table requires a primary key.  The primary key, nor any part of the
primary key, can contain NULL values. This is because NULL values for the
primary key means we cannot identify some rows. For example, in the
EMPLOYEE table, Phone cannot be a key since some people may not have a
phone.

Integrity rule 2: Referential integrity


■ It says that a foreign key must have a matching primary key in a related table
■ This constraint is specified between two tables (parent and child); it
maintains the correspondence between rows in these tables.  It means the
reference from a row in one table to other table must be valid. Examples of
Referential integrity constraint:
Referential integrity Examples
■ In the Customer/Order database:
■ Customer(custid, custname)
■ Order(orderID, custid, OrderDate)
To ensure that there are no orphan records,
we need to enforce referential integrity.
■ An orphan record is one whose foreign
key value is not found in the
corresponding entity – the entity where
the PK is located.  The referential
integrity constraint states that the
CustID in the Order table must match a
valid CustiD in the Customer
table.   Most relational databases have
declarative referential integrity.  In other
words, when the tables are created the
referential integrity constraints are set
up.
Data redundancy
■ Data redundancy means the storage of data in database that is more than
necessary.
■ A good database design makes you enter any data only once and managed in
such a way that the same data will be used wherever required thereafter.
However, a poor designing will fail to achieve that and make the user enter
same data in multiple tables. When you have to supply same data in multiple
tables, it will cause data redundancy.
■ Let’s take an example of School database. Suppose there is a table in
database named Students which stores the information of student like,
registration number, name, father’s name, date of birth, permanent address,
contact number etc.
School:RegistrationNumber, Name, FatherName, DateOfBirth,
PermanentAddress, ContactNumber
Data redundancy cont’d
■ Now, there is another table which contains Fees information of student which
contains fields like student’s name, month, amount, paid date etc.
Fees:ReceiptNumber, StudentName, FeesMonth, FeesAmount, PaidDate
■ Also, there is another table called Marks that stores marks information of student.
This table contains fields like Student Name, Class, Section, Roll Number, Marks in
English, Nepali, Math, etc.
Marks:SlipNumber, StudentName, Class, Section, RollNumber, English, Nepali, Math

Look at this situation. When we already have name field in Student table, the other two
tables Fees and Marks also contain fields StudentName.

In fact, Student’s name field in Fees table and Marks table repeats same data (the name
of any student) two more times unnecessarily. This is called data redundancy.

That was an example of data redundancy existing among multiple tables in a database,
but you can find data redundancy even in a single table.
■ Data redundancy can be minimized or eliminated by a process called normalization.
THE END

You might also like