Lecture Note Unit 1-4
Lecture Note Unit 1-4
UNIT ONE
Introduction
Data, information, information System
Data: is a collection of raw facts.
Information: is a processed data in the form that is meaningful to the user.
Information System is a system that:
Receives data and instruction
Processes the data as per the instruction
Produces output
Stores data/information for future use
Information System and Organization, database system
Information System doesn’t exist without organization. That is, organization of
data is necessary if data is voluminous. Information System is a support
system for the organizational activity to achieve a certain goal.
A database system is basically a computerized record keeping system. Users of
the database can perform a variety of operations. Such as:
Adding new data to empty file
Adding new data to existing file
Retrieving data from existing file
Modifying data to existing file
Deleting data from existing file
Searching for target information
Data handling approaches
There are three levels or types of data handling development/approach. Even
though there is an advantage and a problem overcome at each new data
handling approach/level, all methods or approaches of data handling are in
use to some extent. The major three approaches/levels are discussed as
follows:
1. Manual Approach
In the manual data handling approach, data storage and retrieval follows the
primitive and traditional way of data/information handling where cards and
paper are used for the purpose. Typing the data on paper and put in a file
Page 1
Fundamentals of Database Systems Lecture Note UOG
cabinet. The data storage and retrieval will be performed using human labour.
This approach works well if the number of items to be stored is small.
Limitations of the Manual approach
o Prone to error
o Data loss: Due to damaged papers or unable to locate it.
o Redundancy: Multiple copies of the same data within the organization.
o Inconsistency: Modifications are not reflected on all multiple copies
o Difficult to update, retrieve, integrate
o You have the data but it is difficult to compile the information
o Limited to small size information
An alternative approach of data handling is a computerized way of dealing with
the information. The computerized approach could also be either
decentralized or centralized base on where the data resides in the system.
2. File based Approach
There were, and still are, several computer applications with file based
processing used for the purpose of data handling. It is a collection of
application programs that performs services for the end users. In such
systems, every application program that provides service to end users define
and manage its own data. Such systems have number of programs for each of
the different applications in the organization. And this approach is the
decentralized computerized data handling method.
Limitations of the File Based approach
The shortcomings of file based approach include, but not limited to:
Separation/Isolation of data
When data is isolated in separate files, it is difficult to access data that should
be available. This is because; there is no concept of relationship between files.
Therefore, we need to create a temporary file for the participating files.
Duplication of data (Redundancy)
This is concerning with storage of similar information in multiple files.
The following are some of the disadvantage of redundancy:
It costs time and money to enter the data
Page 2
Fundamentals of Database Systems Lecture Note UOG
It takes up additional storage space (memory space)
Inconsistency: this is loss of data integrity. For instance, if modification
in the child table is unable to be reflected on the parent table.
Data Dependence
Changes to an existing structure are difficult to make. Example: change in the
size of Student Name (from 20 characters to 30 characters) requires a new
program to convert student file to a new format. The new program opens
original student file, open a temporary file, read records from original student
file and write to the temporary file, delete the original student file and finally
rename the temporary file as student file. It is time consuming and Prone to
error.
Incompatible file formats
The structure of file is dependent on the application programs. Incompatibility
of files makes them difficult to process jointly. Example: consider two files with
in the same enterprise but in different departments, or in different branches: If
the first file is constructed using COBOL and the second file is written using
C++, then there will be a problem of integrity.
3. Database Approach
What is a Database?
A database is a collection of related data in an organized way. Most of the time,
organization is in tabular form. E.g. book database
Call no Title Author Publisher No of copies
QA46 Introduction to database Bahiru Addison Wesley 15
Page 3
Fundamentals of Database Systems Lecture Note UOG
What is a database system?
It is a computerized record keeping system or a kind of electronic filing cabinet, which stores
related data in an organized way. The overall purpose of a database system is to store
information and to allow users to add, delete, retrieve, search, query and update that information
upon request.
Thus in database approach:
Database is a repository for collection of computerized data files.
Database is a shared collection of logically related data designed to meet the information
needs of an organization. Since it is a shared corporate resource, the database is integrated
with minimum amount of or no duplication.
In addition to containing data required by an organization, database also contains a
description of the data which called as “Metadata” or “Data Dictionary” or “Systems
Catalogue” or “Data about Data”. Since a database contains information about the data
(metadata), it is called a self descriptive collection on integrated records.
Unlike the traditional file based approach in database approach there is program data
independence. That is the separation of the data definition from the application.
Page 4
Fundamentals of Database Systems Lecture Note UOG
change is made to a particular data (among the common ones) this change
need to be done throughout the system where there is such data stored.
Security restrictions can be applied: Since the data is stored in one
place/area all accesses to the data can be regulated by the system through
some defined rules built into the system.
Less labour: unlike the other data handling methods, data maintenance will
not demand much resource.
Centralized information control: since relevant data in the organization will
be stored at one repository, it can be controlled and managed at the central
level.
Page 5
Fundamentals of Database Systems Lecture Note UOG
Hardware: This portion of the system consists of secondary storage media
(disks, tapes and optical media) that are used to hold the stored data and
associated device controllers (hard disk controller, etc.); and the processor(s)
and associated main memory that are used to support the execution of the
database system software.
Software: This is the software, Database Management System (DBMS) that is
responsible for the overall management of communications between the user
and the database. That means the data is entirely covered or shielded by the
DBMS software. The DBMS provides facilities for operating on the database.
Users and Designers of Database: As people are one of the components in
DBS environment, there are group of roles played by different stakeholders of
the designing and operation of a database system.
Page 6
Fundamentals of Database Systems Lecture Note UOG
1. Database Administrator (DBA)
Responsible to oversee, control and manage the database resources (the database
itself, the DBMS and other related software)
Authorizing access to the database
Coordinating and monitoring the use of the database
Responsible for determining and acquiring hardware and software resources
Accountable for problems like poor security, poor performance of the system
Involves in all steps of database development
We can have further classifications of this role in big organizations having huge
amount of data and user requirement.
Page 7
Fundamentals of Database Systems Lecture Note UOG
o Liaising with users: By communicating with users the DBA
will ensure that the data they require is available, and to
write (or help users write) the necessary external schemas
using the applicable external DDL.
o Defining security and integrity rules: Since security and
integrity rules are part of the conceptual schema, the
conceptual DDL should include facilities for specifying such
rules.
o Defining backup and recovery procedures: In the event of
damage to any portion of a database, it is essential to be able
to repair the data. The DBA should define and implement
appropriate backup and recovery scheme.
2. Database Designer (DBD)
Identifies the data to be stored and choose the appropriate structures to represent
and store the data.
Should understand the user requirement and should choose how the user views
the database.
Involve on the design phase before the implementation of the database system.
We have two distinctions of database designers, one involving in the logical and
conceptual design and another involving in physical design.
Page 8
Fundamentals of Database Systems Lecture Note UOG
Physical DBD
Take logical design specification as input and decide how it should be
physically realized.
Map the logical data model on the specified DBMS with respect to
tables and integrity constraints. (DBMS dependent designing)
Select specific storage structure and access path to the database
Design security measures required on the database
3. Application Programmer and Systems Analyst
System analyst determines the user requirement and how the user wants to
view the database.
The application programmer implements these specifications as programs;
code, test, debug, document and maintain the application program.
Determines the interface on how to retrieve, insert, update and delete
data in the database.
4. End-users: These are those people who are engaged on processing different
types of operations on the database system. Users are workers, whose job
requires accessing the database frequently for various purpose. There are
different group of users in this category.
Naïve Users:
Sizable proportion of users
Unaware of the DBMS
Only access the database based on their access level and
demand
Use standard and pre-specified types of queries.
Sophisticated Users
Are users familiar with the structure of the Database and
facilities of the DBMS.
Have complex requirements
Have higher level queries
Are most of the time engineers, scientists, business analysts,
etc
Page 9
Fundamentals of Database Systems Lecture Note UOG
Casual Users
Users who access the database occasionally.
Need different information from the database each time.
Use sophisticated database queries to satisfy their needs.
Are most of the time middle to high level managers.
These users can be again classified as “Actors on the Scene” and “Workers Behind the
Scene”.
Actors On the Scene:
Data Administrator
Database Administrator
Database Designer
End Users
Workers Behind the Scene
DBMS designers and implementers: who design and implement different
DBMS software.
Tool Developers: experts who develop software packages that facilitates
database system designing and use. Prototype, simulation, code generator
developers could be an example. Independent software vendors could also be
categorized in this group.
Operators and Maintenance Personnel: system administrators who are
responsible for actually running and maintaining the hardware and software of
the database system and the information technology facilities.
Page 10
Fundamentals of Database Systems Lecture Note UOG
- Sharing: allows multiple users to access data.
A DBMS is software that enables users to define, create, maintain and control
access to the database. Example: Ms Access, FoxPro, SQL Server, MySQL,
Oracle.
Each DBMS should have facilities to define the database, manipulate the
content of the database and control the database. It provides the following
facilities:
Data Definition Language (DDL):
Page 11
Fundamentals of Database Systems Lecture Note UOG
o Language used to define each data element required by the organization.
o Commands for setting up schema or the intension of database
o These commands are used to setup a database, create, delete and alter
table with the facility of handling constraints
o Allows DBA or user to describe and name entitles, attributes and
relationships required for the application.
Data Manipulation Language (DML):
o Is a core command used by end-users and programmers to store, delete,
and upate the data in the database.
o Provides basic data manipulation operations on data held in the database.
o Language for manipulating the data organized by the appropriate data model
Data Query Language (DQL):
o Language for accessing or retrieving the data organized by the appropriate data
model.
o Since the required data or Query by the user will be extracted using this
type of language, it is also called "Query Language"
o Procedural DQL: user specifies what data is required and how to get the data.
o Non-Procedural DQL: user specifies what data is required but not how it is to be
retrieved
Data Dictionary (DD):
o Due to the fact that a database is a self describing system, this tool, Data
Dictionary, is used to store and organize information about the data
stored in the database.
Data Control Language (DCL):
o Data Control Languages are commands that will help the Database
Administrator to control the database.
o The commands include grant or revoke privileges to access the database
or particular object within the database and to store or remove database
transactions
Page 12
Fundamentals of Database Systems Lecture Note UOG
Database System Development Life Cycle
There are several steps in developing a database system. The major steps in
database system development are;
1. Planning: That is identifying information gap in an organization and propose a
database solution to solve the problem.
2. Analysis: That concentrates more on fact finding about the problem or the
opportunity. Feasibility analysis, requirement determination and structuring,
and selection of best design method are also performed at this phase.
3. Design: In database system development more emphasis is given to this phase.
The phase is further divided into three sub-phases.
A. Conceptual Design: Concise description of the data, data type,
relationship between data and constraints on the data.
There is no implementation or physical detail consideration.
Used to elicit and structure all information requirements.
B. Logical Design: A higher level conceptual abstraction with selected
specific database model to implement the data structure.
It is particular DBMS independent and with no other physical
considerations.
C. Physical Design: Physical implementation of the upper level design of the
database with respect to internal storage and file structure of the database
for the selected DBMS.
To develop all technology and organizational specification.
4. Implementation: The testing and deployment of the designed database for use.
5. Operation and Support: administering and maintaining the operation of the
database system and providing support to users.
Page 13
Fundamentals of Database Systems Lecture Note UOG
ANSI-SPARC Architecture and Database Design Phases
The Database System Architecture is consists of the three levels: External level,
conceptual level, Internal level.
External Level:
The external level is the one closest to the users, i.e., it is the one concerned
with the way the data is viewed by individual users. An external view is the
content of the database as seen by some particular user.
Each external view is defined by a means of an external schema. This
schema is written using the external DDL portion of the user’s data sub
language.
External level is users' view of the database. Different users have their own
customized view of the database independent of other users.
Conceptual Level:
o The conceptual level is found in between the other two. It is a representation
of the entire information content of the database including the relations
with one another and security and integrity rules, etc.
o It is the view of the data as it really is or by its entirety rather than as users
are forced to see.
o The conceptual view is defined by means of the conceptual schema, which is
written using another DDL.
o The conceptual schema includes a great many additional features, such as
the security and integrity rules.
o Conceptual level is community view of the database. Describes what data is
stored in database and relationships among the data.
Internal Level:
It is the one closest to the physical storage, i.e., it is concerned with the way
the data is physically stored.
The internal view is described by means of the internal schema, which not
only defines the various stored record types but also specifies what indexes
Page 14
Fundamentals of Database Systems Lecture Note UOG
exist, how stored fields are represented, what physical sequence the stored
records are in, and so on. The internal schema is written using yet another
DDL-the internal DDL.
Internal level is the physical representation of the database on the
computer. Describes how the data is stored in the database.
The following example can be taken as an illustration for the difference
between the three levels in the ANSI-SPARC database system Architecture.
Where:
The first level is concerned about the group of users and their respective
data requirement independent of the other.
The second level is describing the whole content of the database where
one piece of information will be represented once.
The third level
Page 15
Fundamentals of Database Systems Lecture Note UOG
Page 16
Fundamentals of Database Systems Lecture Note UOG
UNIT TWO
Database Model
A database model is a conceptual description of how the database works. It
describes how the data elements are stored in the database and how the data
is presented to the user and programmer for access; and the relationship
between different items in the database.
A specific DBS has its own specific Data Definition Language, but this type of
language is too low level to describe the data requirements of an organization
in a way that is readily understandable by a variety of users. We need a higher-
level language. Such a higher-level is called database model.
Object-based
Record-based
Physical
Page 17
Fundamentals of Database Systems Lecture Note UOG
Page 18
Fundamentals of Database Systems Lecture Note UOG
Relation is established by creating physical link between stored records
(each is stored with a predefined access path to other records)
To add new record type or relationship, the database must be redefined
and then stored in a new form.
Department
Employee Job
2. Network Model
The network is a conceptual description of databases where many-to-many
(multiple parent-children) relationships exist. To make this model easier to
understand, the relationships between the different data items are commonly
Page 19
Fundamentals of Database Systems Lecture Note UOG
referred to as sets to distinguish them from the strictly parent-child
relationships defined by the HDBM.
The network model uses pointers to map the relationships between the
different data items. The flexibility of the NDB model is in showing many-to-
many relationships is its greatest strength, though the flexibility comes at a
price (the interrelationships between the different data sets become extremely
complex and difficult to map).
Like the HDBM, NDBMs can very quickly be searched, especially through the
use of index pointers that lead directly to the first item in a set being searched.
The NDBM suffers from the same structural problem as the HDBM; the initial
design of the database is arbitrary, and once its setup, any changes to the
different sets require the programmer to create an entirely new structure. The
dual problems of duplicated data and inflexible structure led to the
development of a database model that minimizes both problems by making
relationships between the different data items the foundation for how the
database is structure.
Department Job
Employee
Activity
Page 20
Time Card
Fundamentals of Database Systems Lecture Note UOG
The primary purpose behind the relational database model is the preservation
of data integrity. To be considered truly relational, a DBMS must completely
prevent access to the data by any means other than queries handled by the
DBMS itself. While the relational model does not specify how the data is stored
on the disk, the preservation of data integrity implies that the data must be
stored in a format that prevents it from being accessed from outside the DBMS
that created it.
Page 21
Fundamentals of Database Systems Lecture Note UOG
The relational model also requires that the data be accessed through programs
that don’t rely on the position of the data in the database. This is in direct
contrast to the other database models, where the program has to follow a series
of pointers to the data it wants. A program querying a relational database
simply asks for the data it wants, and it is up to the DBMS to do the necessary
searches and provide the answer. Searches can be speed up by creating an
index on one or more columns in a table; however, the DBMS controls and
uses the index. The user has only to ask the DBMS to create the index, and it
will be maintained and used automatically from that point on.
The relational database model has a number of advantages over the other
models. The most important is its complete flexibility in describing the
relationships between the various data items. Once the tables are created and
relationships defined then users can query the database on any of the
individual columns in a table or on the relationships between the different
tables.
Changing the structure of the database objects is as simple as adding or
deleting columns in a table. Creating new tables, deleting old tables etc. are
also very simple. The major tasks that the designers of a relational database
has to make concerns the definitions of the tables and their relationships in
the database.
Page 22
Fundamentals of Database Systems Lecture Note UOG
A row of the table is called tuple equivalent to record.
A column of a table is called attribute equivalent to fields.
Data value is the value of the Attribute.
Records are related by the data stored jointly in the fields of records in
two tables or files. The related tables contain information that creates
the relation.
The tables seem to be independent but are related some how.
No physical consideration of the storage is required by the user.
Many tables are merged together to come up with a new virtual view
of the relationship.
Alternative terminologies
Relation Table File
Tuple Row Record
Attribute Column Field
Page 23
Fundamentals of Database Systems Lecture Note UOG
UNIT THREE
Database Modeling Using the Relational Database Model
Properties of Relational Databases - Basic Concepts in Relational Database
Each row of a table is uniquely identified by a primary key (can be
composed of one or more columns).
Each tuple in a relation must be unique.
Group of columns, that uniquely identifies a row in a table is called a
candidate key.
Entity integrity rule of the model states that no component of the
primary key may contain a NULL value.
A column or combination of columns that matches the primary key of
another table is called a foreign key. This key is used to cross-
reference tables.
The referential integrity rule of the model states that, for every foreign
key value in a table there must be a corresponding primary key value
in another table in the database or it should be NULL.
All tables are logical entities.
A table is either a base tables (named relations) or views (unnamed
relations).
Only base tables are physically stores.
Views are derived from base tables with SQL instructions like:
[select .. from .. where .. order by].
Relatioal database is the collection of tables.
Each entity in one table.
Attributes are fields (columns) in table.
Order of rows and columns is immaterial or irrelevant.
Entries with repeating groups are said to be un-normalized.
Entries are single-valued.
Page 24
Fundamentals of Database Systems Lecture Note UOG
Each column (field or attribute) has a distinct name.
All values in a column represent the same attribute and have the same data
format.
Building Blocks of the Relational Database Model
The building blocks of the relational database model are:
Entities: Real world physical or logical object.
Attributes: Properties used to describe each Entity or real world object.
Relationship: The association between the real world objects (i.e Entities.)
Constraints: Rules that should be obeyed or followed while manipulating
the data.
1. ENTITIES: The entities (persons, places, things etc.) which the
organization has to deal with. Relations can also describe relationships. The
name given to an entity should always be a singular noun descriptive of
each item to be stored in it. E.g.: student, NOT students. Every relation has
a schema, which describes the columns, or fields, the relation itself
corresponds to our familiar notion of a table: A relation is a collection of
tuples, each of which contains values for a fixed number of attributes.
Existence Dependency: The dependence of an entity on the existence
of one or more entities.
Weak entity : An entity that can not exist without the entity with
which it has a relationship – it is indicated by a double rectangle.
2. ATTRIBUTES - The items of information which characterize and describe
these entities. Attributes are pieces of information about entities. The
analysis must of course identify those which are actually relevant to the
proposed application. Attributes will give rise to recorded items of data in
the database. At this level we need to know such things as:
Attribute name: Should be explanatory words or phrases.
The domain: From which attribute values are taken (A domain is a
set of values from which attribute values may be taken.) Each
attribute has values taken from a domain. For example, the
domain of Name is string and that for salary is real.
Page 25
Fundamentals of Database Systems Lecture Note UOG
Whether the attribute is part of the entity identifier (attributes
Types of Attributes
(1) Simple (atomic) Vs Composite attributes
Simple : Contains a single value (not divided into sub parts)
E.g. Age, gender,etc.
Composite: Divided into sub parts (composed of other attributes).
E.g. Name, address,etc.
(2) Single-valued Vs multi-valued attributes
Single-valued : Have only single value (the value may change but
has only one value at one time).
E.g. Name, Sex, Id. No. color_of_eyes, etc.
Multi-Valued: Type of attribute that can have more than one value
at a time.
E.g. Address, dependent-name, Person may have
several college degrees, etc.
(3) Stored vs. Derived Attributes
Stored : Not possible to derive or compute the values of stored
attributes.
E.g. Name, Address, etc.
Derived: The value of drived attribute may be derived (computed)
from the values of other attributes.
E.g. Age (current year – year of birth).
Length of employment (current date - start date).
Profit (earning - cost).
Page 26
Fundamentals of Database Systems Lecture Note UOG
G.P.A (grade point/credit hours).
(4) Null Values
NULL applies to attributes which are not applicable or which do
not have values.
You may enter the value NA (meaning not applicable).
Value of a key attribute can not be null.
Employees by a relationship)?
If we have several addresses per employee, address must be an
entity (attributes cannot be set-valued/multi valued).
Page 27
Fundamentals of Database Systems Lecture Note UOG
Role names are different from the names of entities forming the
relationship: one entity may take on many roles, the same role may
be played by different entities.
For each relationship, one can talk about the number of entities
and the number of tuples participating in the association. These
two concepts are called degree and cardinality of a relationship
respectively.
Degree of a Relationship
Degree of relationship is an important point about a relationship which
concerns how many entities are participate in it. The number of entities
participating in a relationship is called the degree of the relationship. Among
the Degrees of relationship, the following are the basic:
Unary/recursive relationship: Tuples/records of a single entity are
related with each other.
Binary relationships: Tuples/records of two entities are associated in a
relationship.
Ternary relationship: Tuples/records of three different entities are
associated.
n-nary relationship: A generalized degree of relationship in which tuples
from arbitrary number of entity sets are participating in a relationship.
Page 28
Fundamentals of Database Systems Lecture Note UOG
Cardinality of a Relationship
Another important concept about relationship is the number of
instances/tuples that can be associated with a single instance from one entity
in a single relationship. The number of instances participating or associated
with a single instance from an entity in a relationship is called the cardinality
of the relationship. The major cardinalities of a relationship are:
One-to-one: one tuple is associated with only one other tuple.
o E.g. Building -to- Location as a single building will be located in a
single location and as a single location will only accommodate a
single Building.
One-to-many: one tuple can be associated with many other tuples, but not
the reverse.
o E.g. Department-to-Student as one department can have multiple
students.
Many-to-one: many tuples are associated with one tuple but not the
reverse.
o E.g. Employee –to-Department: as many employees belong to a single
department.
Many-to-many: one tuple is associated with many other tuples and from
the other side, with a different role name one tuple will be
associated with many tuples.
o E.g. Student–to-Course as a student can take many courses and a
single course can be attended by many students.
Page 29
Fundamentals of Database Systems Lecture Note UOG
4. Relational Constraints/Integrity Rules
Relational Integrity:
Domain integrity: No value of the attribute should be beyond the
allowable limits.
Entity integrity: In a base relation, no attribute of a Primary Key can
assume a value of NULL.
Referential integrity: If a Foreign Key exists in a relation, either the
Foreign Key value must match a Candidate Key value in its home
relation or the Foreign Key value must be NULL.
Enterprise integrity: Additional rules specified by the users or
database administrators of a database are incorporated.
Page 30
Fundamentals of Database Systems Lecture Note UOG
- “EmpId”, “NationalId”, “Name, BDate” (assuming that there is no coincidence
that employees with the same name may born on the same day) … are
candidate keys.
The designer of the database is the one that makes the choice of the candidate
keys for implementation, but the choice has to be made carefully. Primary key
is a term used to refer to the candidate key that is selected by the designer for
implementation.
Candidate Key: an attribute or set of attributes that uniquely identifies
individual occurrences of an entity type or tuple within a relation.
A candidate key has two properties:
1. Uniqueness
2. Irreducibility
Candidate Key: a super key such that no proper subset of that collection is a
Super Key within the relation.
Relational Views
Relations are perceived as a table from the users’ perspective. Actually, there
are two kinds of relation in relational database. The two categories or types of
relations are Base (Named) and View (Unnamed) Relations. The basic difference
is on how the relation is created, used and updated:
Page 31
Fundamentals of Database Systems Lecture Note UOG
1. Base Relation: A named relation corresponding to an entity in the
conceptual schema, whose tuples are physically stored in the database.
2. View (Unnamed Relation): A View is the dynamic result of one or more
relational operations operating on the base relations to produce another
virtual relation that does not actually exist as presented. So a view is
virtually derived relation that does not necessarily exist in the database
but can be produced upon request by a particular user at the time of
request. The virtual table or relation can be created from single or
different relations by extracting some attributes and records with or
without conditions.
Purpose of a view
Hides unnecessary information from users: since only part of the base
relation (Some collection of attributes, not necessarily all) are to be
included in the virtual table.
Provide powerful flexibility and security: since unnecessary information
will be hidden from the user there will be some sort of data security.
Provide customized view of the database for users: each users are going
to be interfaced with their own preferred data set and format by making
use of the Views.
A view of one base relation can be updated.
Update on views derived from various relations is not allowed since it
may violate the integrity of the database.
Update on view with aggregation and summary is not allowed. Since
aggregation and summary results are computed from a base relation and
does not exist actually.
Page 32
Fundamentals of Database Systems Lecture Note UOG
and the relations with some information at some point in time is the Instance
or the flesh of the database.
Schemas
Schema describes how data is to be structured, defined at setup/design time
(also called "metadata"). Since it is used during the database development
phase, there is rare tendency of changing the schema unless there is a need for
system maintenance which demands change to the definition of a relation.
Database Schema (Intension): specifies name of relation and the
collection of the attributes (specifically the Name of attributes).
Refer to a description of database (or intention)
Specified during database design
Should not be changed unless during maintenance
Schema Diagrams: convention to display some aspect of a schema
visually.
Schema Construct: refers to each object in the schema (e.g. STUDENT)
E.g.: STUNEDT (FName,LName,Id,Year,Dept,Sex)
Instances
Instance: is the collection of data in the database at a particular point of time
(snap-shot).
Also called State or Snap Shot or Extension of the database.
Refers to the actual data in the database at a specific point in time.
State of database is changed any time we add, delete or update an
item.
Valid state: the state that satisfies the structure and constraints
specified in the schema and is enforced by DBMS.
Since instance is actual data of database at some point in time, changes
rapidly. To define a new database, we specify its database schema to the DBMS
(database is empty). Database is initialized when we first load it with data.
Strong
WeakEntity
Entity
Page 34
Fundamentals of Database Systems Lecture Note UOG
The whole purpose of ER modeling is to create an accurate reflection of the real world in a
database. The ER model doesn’t actually give us a database description. It gives us an
intermediate step from which it is easy to define a database.
The E-R data model is based on a perception of a real world that consists of a set of basic objects
called entities, and of relationships among these objects. It was developed to facilitate database
design by allowing the specification of an enterprise schema, which represents the overall logical
structure of a database.
The E-R data model is one of several semantic data models; the semantic aspect of the model lies
in the attempt to represent the meaning of the data. The E-R model is extremely useful in
mapping the meanings and interactions of real-world enterprises onto a conceptual scheme.
Because of this utility, many database design tools draw on concepts from the E-R model.
A data model in which information stored in the database is viewed as sets of entities and sets of
relationships among entities. There are four basic notions that the ER Model employs: entity
sets/type, relationships, attributes, and constraints.
Page 35
Fundamentals of Database Systems Lecture Note UOG
UNIT FOUR
Database Design
Database design is the process of coming up with different kinds of
specification for the data to be stored in the database. The database design
part is one of the middle phases we have in information systems development
(DBS) where the system uses a database approach. Design is the part on which
we would be engaged to describe how the data should be perceived at different
levels and finally how it is going to be stored in a computer system.
Page 36
Fundamentals of Database Systems Lecture Note UOG
What are the other requirements of the Organization and the Users
Conceptual Design
Logical Design
Physical Design
Normalization process
– Collection of Rules to be maintained.
– Discover new entities in the process.
Page 37
Fundamentals of Database Systems Lecture Note UOG
– Revise attributes based on the rules and the discovered Entities.
NOTE:
In conceptual data model/Design
o Identify what are the entities/entity types
o Identify what are the attributes: - the information about entities and relationship should we store
in the database.
o Identify relationship types
o Identify what are the constraints/business rules that hold?
o Draw entity-relationship diagram:- representing the database in the ER model using pictorial
representation called ER diagram
o Review the conceptual data model with user
In logical data model/Design
o Map the conceptual model to a logical model
o Mapping entities and relationships in ER-Diagram into tables
-Translate ER-diagram with constraints
o Derive relations from the logical data model
o Validate model using normalization
o Validate model against user transactions
o Draw entity-relationship diagram
o Define integrity constraints
o Check for future growth
Page 38
Fundamentals of Database Systems Lecture Note UOG
NB: Startng from this we are going to design database using the relational
database model.
Page 39
Fundamentals of Database Systems Lecture Note UOG
o Represented by Diamond
Constraints
o Represent the constraint in the data
Before working on the conceptual design of the database, one has to know
and answer the following basic questions.
What are the entities and relationships in the enterprise?
What information about these entities and relationships should we
store in the database?
What are the integrity constraints that hold? Constraints on each data
with respect to update, retrieval and store.
Represent this information pictorially in ER diagrams, then map ER
diagram into a relational schema.
The basic E-R model is graphically depicted and presented for review. The
process is repeated until the end users and designers agree that the E-R
diagram is a fair representation of the organization’s activities and functions.
Checking for Redundant Relationships in the ER Diagram. Relationships
between entities indicate access from one entity to another - it is therefore
possible to access one entity occurrence from another entity occurrence even if
there are other entities and relationships that separate them - this is often
Page 40
Fundamentals of Database Systems Lecture Note UOG
referred to as Navigation' of the ER diagram. The last phase in ER modeling is
validating an ER Model against requirement of the user.
Id Gpa
Students Course
s
Age
Enrolled_In Semester
Academic
Year
Grade
Page 41
Fundamentals of Database Systems Lecture Note UOG
1. Constraints on Relationship/Multiplicity/ Cardinality Constraints: Multiplicity
constraint is the number or range of possible occurrence of an entity type/relation that may
relate to a single occurrence/tuple of an entity type/relation through a particular
relationship. Mostly used to insure appropriate enterprise constraints.
One-to-one relationship:
A customer is associated with at most one loan via the relationship
borrower.A loan is associated with at most one customer via borrower.
1..1 0..1
Employee Manages Branch
One-To-Many Relationships
In the one-to-many relationship a loan is associated with at most one
customer via borrower, a customer is associated with several (including 0) loans via
borrower.
Page 42
Fundamentals of Database Systems Lecture Note UOG
1..1 0..*
Employee Leads Project
Many-To-Many Relationship
A customer is associated with several (possibly 0) loans via borrower. A
loan is associated with several (possibly 0) customers via borrower.
0..* 1..*
Instructor Teaches Course
Page 43
Fundamentals of Database Systems Lecture Note UOG
2. Participation of an Entity Set in a Relationship Set=Particpation constraints
Participation constraint of a relationship is involved in identifying and setting the
mandatory or optional feature of an entity occurrence to take a role in a relationship.
There are two distinct participation constraints with this respect, namely: Total
Participation and Partial Participation.
1. Total participation: every tuple in the entity or relation participates in at least
one relationship by taking a role. This means, every tuple in a relation will be
attached with at least one other tuple. The entity with total participation in a
relationship will be connected to the relationship using a double line.
2. Partial participation: some tuple in the entity or relation may not participate in
the relationship. This means, there is at least one tuple from that Relation not
taking any role in that specific relationship. The entity with partial participation
in a relationship will be connected to the relationship using a single line.
E.g. 1: Participation of EMPLOYEE in “belongs to” relationship with
DEPARTMENT is total since every employee should belong to a department.
Participation of DEPARTMENT in “belongs to” relationship with
EMPLOYEE is total since every department should have more than one
employee.
Problem in ER Modeling
Page 44
Fundamentals of Database Systems Lecture Note UOG
The Entity-Relationship Model is a conceptual data model that views the real world as
consisting of entities and relationships. The model visually represents these concepts by
the Entity-Relationship diagram. The basic constructs of the ER model are entities,
relationships, and attributes. Entities are concepts, real or abstract, about which
information is collected. Relationships are associations between the entities. Attributes
are properties which describe the entities.
While designing the ER model one could face a problem on the design which is called a
connection traps. Connection traps are problems arising from misinterpreting certain
relationships.
There are two types of connection traps;
1. Fan trap:
Occurs where a model represents a relationship between entity types, but the
pathway between certain entity occurrences is ambiguous.
May exist where two or more one-to-many (1:M) relationships fan out from an
entity. The problem could be avoided by restructuring the model so that there
would be no 1:M relationships fanning out from a singe entity and all the
semantics of the relationship is preserved.
Example:
1..* 1..1 IsAssigned
EMPLOYEE Works BRANCH 1..*
CAR
1..1
Page 45
Fundamentals of Database Systems Lecture Note UOG
Problem: Which car (Car1 or Car3 or Car5) is used by Employee 6. Emp6 working in
Branch 1 (Bra1). Thus from this ER Model one can not tell which car is used by which
staff since a branch can have more than one car and also a branch is populated by more
than one employee. Thus we need to restructure the model to avoid the connection trap.
To avoid the Fan Trap problem we can go for restructuring of the E-R Model. This will
result in the following E-R Model.
1..1 Has 1..* Used
BRANCH 1..* CAR By 1..* EMPLOYEE
Car1
Bra1 Emp1
Car2
Bra2 Emp2
Car3
Bra3 Emp3
Car4
Bra4 Emp4
Car5
Emp5
Car6
Emp6
Car7
2. Chasm Trap: Emp7
Occurs where a model suggests the existence of a relationship between entity
types, but the path way does not exist between certain entity occurrences.
May exist when there are one or more relationships with a minimum multiplicity
on cardinality of zero forming part of the pathway between related entities.
Example:
1..1 Has
BRANCH 1..*
EMPLOYEE 0..1
0..*
Manages PROJECT
If we have a set of projects that are not active currently then we can not assign a project
manager for these projects. So there are project with no project manager making the
participation to have a minimum value of zero.
Problem:
How can we identify which BRANCH is responsible for which PROJECT? We know
that whether the PROJECT is active or not there is a responsible BRANCH. But which
Page 46
Fundamentals of Database Systems Lecture Note UOG
branch is a question to be answered, and since we have a minimum participation of
zero between employee and PROJECT we can’t identify the BRANCH responsible for
each PROJECT.
The solution for this Chasm Trap problem is to add another relationship between the
extreme entities (Branch and Project).
1..1 Has
BRANCH 1..*
EMPLOYEE 0..1
0..*
Manages PROJECT
Page 47
Fundamentals of Database Systems Lecture Note UOG
EER Concepts: In this part we will discuss the following basic EER concepts.
Generalization
Specialization
Sub classes
Super classes
Attribute Inheritance
Constraints on specialization and generalization
Generalization
Generalization occurs when two or more entities represent categories of the same
real-world object. Generalization is the process of defining a more general entity
type from a set of more specialized entity types. A generalization hierarchy is a form
of abstraction that specifies that two or more entities that share common attributes
can be generalized into a higher level entity type. Generalization is considered as
bottom-up definition of entities. Generalization hierarchy depicts relationship
between higher level superclass and lower level subclass.
Generalization hierarchies can be nested. That is, a subtype of one hierarchy can be a
supertype of another. The level of nesting is limited only by the constraint of
simplicity.
Example: Account is a generalized form for Saving and Current Accounts.
Page 48
Fundamentals of Database Systems Lecture Note UOG
Specialization
Specialization is the result of subset of a higher level entity set to form a lower level
entity set. The specialized entities will have additional set of attributes (distinguishing
characteristics) that distinguish them from the generalized entity. Is considered as Top-
Down definition of entities. Specialization process is the inverse of the Generalization
process. Identify the distinguishing features of some entity occurrences, and specialize
them into different subclasses.
Page 49
Fundamentals of Database Systems Lecture Note UOG
Subclass/Subtype
An entity type whose tuples have attributes that distinguish its members from tuples of
the generalized or Superclass entities. When one generalized Superclass has various
subgroups with distinguishing features and these subgroups are represented by
specialized form, the groups are called subclasses. Subclasses can be either mutually
exclusive (disjoint) or overlapping (inclusive). A single subclass may inherit attributes
from two distinct superclasses. A mutually exclusive category/subclass is when an
entity instance can be in only one of the subclasses. E.g.: An EMPLOYEE can either be
SALARIED or PART-TIMER but not both.
Superclass /Supertype
An entity type whose tuples share common attributes. Attributes that are shared by all
entity occurrences (including the identifier) are associated with the supertype.
Superclass /Supertype Is the generalized entity.
Page 50
Fundamentals of Database Systems Lecture Note UOG
Manager IS AN Employee
All subclasses or specialized entity sets should be connected with the superclass using a
line to a circle where there is a subset symbol indicating the direction of
subclass/superclass relationship.
Attribute Inheritance
An entity that is a member of a subclass inherits all the attributes of the entity as a
member of the superclass. The entity also inherits all the relationships in which the
superclass participates. An entity may have more than one subclass categories. All
entities/subclasses of a generalized entity or superclass share a common unique
identifier attribute (primary key). i.e. The primary key of the superclass and subclasses
are always identical.
Page 51
Fundamentals of Database Systems Lecture Note UOG
Consider the EMPLOYEE supertype entity shown above. This entity can have several
different subtype entities (for example: HOURLY and SALARIED), each with distinct
properties not shared by other subtypes. But whether the employee is Hourly or
Salaried, same attributes (EmployeeId, Name, and DateHired) are shared. The
Supertype EMPLOYEE stores all properties that subclasses have in common. And
HOURLY employees have the unique attribute Wage (hourly wage rate), while
SALARIED employees have two unique attributes, StockOption and Salary.
Page 52
Fundamentals of Database Systems Lecture Note UOG
The
Partial Specialization Rule specifies that it is not necessary for all entity occurrences in
the superclass to be a member of one of the subclasses. Here we have an optional
participation on the specialization. Partial Participation of superclass instances on
subclasses is diagrammed with a single line from the Supertype to the circle. E.g.: If we
have Manager and Secretary as subclasses of a superclass Employee, then it is not the
case that all employees are either manager or secretary. Thus the participation of
instances of employee in manager and secretary subclasses will be partial.
Disjointness Constraints
Specifies the rule whether one entity occurrence can be a member of more than one
subclasses. i.e. it is a type of business rule that deals with the situation where an entity
occurrence of a Superclass may also have more than one Subclass occurrence. The
Disjoint Rule restricts one entity occurrence of a superclass to be a member of only one
of the subclasses. Example: a Employee can either be salaried or part-timer, but not the
both at the same time. The Overlap Rule allows one entity occurrence to be a member f
more than one subclass. Example: Employee working at the university can be both a
Student and an employee at the same time. This is diagrammed by placing either the
letter "d" for disjoint or "o" for overlapping inside the circle on the Generalization
Hierarchy portion of the E-R diagram.
Page 53
Fundamentals of Database Systems Lecture Note UOG
The two types of constraints on generalization and specialization (Disjointness and
Completeness constraints) are not dependent on one another. That is, being disjoint
will not favour whether the tuples in the superclass should have Total or Partial
participation for that specific specialization.
From the two types of constraints we can have four possible constraints
@ Disjoint AND Total
Page 54