Design Database Main Module Simplified Tvet
Design Database Main Module Simplified Tvet
Design Database Main Module Simplified Tvet
Department ICT
Database Administration level III
Unit of competence: Design a database
LEARNING OUTCOMES:
• LO1 Determine database requirements
• LO2 Develop logical data model
• LO3 Design data structures
• LO4 Design queries, screens and reports
• LO5 Design access and security systems
• LO6 Confirm database design compiled by Aliyan A.
1
Introduction
• Data: What is data?
• Facts concerning people, objects, events or other entities.
• Can be in the form of text, graphics, sound and video segments
• They are difficult to interpret or make decisions based on
• Unprocessed, raw facts and can be stored in database
2
Introduction … cont’d
What is database?
• Database is a collection of related data and data is a collection of
facts and figures that can be processed to produce information.
• An organized collection of logically related data.
• A shared collection of logically interrelated data designed to meet
the varied information needs of an organization
• A shared collection – can be used simultaneously by many
department and user
• Logically related - comprise the important objects and the
relationships between these objects
• A computerized means of record keeping system
3
Introduction …. cont’d
A database has the following implicit properties:
• A database represents some aspect of the real world, sometimes called
the mini world or the Universe of Discourse (UoD).
• Changes to the mini world are reflected in the database.
• A database is a logically coherent collection of data with some inherent
meaning.
• A random assortment of data cannot correctly be referred to as a
database.
• A database is designed, built, and populated with data for a specific
purpose.
4
Introduction …. cont’d
Data
Course Section Semester Name Rank
5
Introduction … cont’d
Meta Data: What do we mean by meta data?
Descriptions of the properties or characteristics of the data,
including data types, field sizes, allowable values, and
documentation
Data that describes data
Data about data
Description of fields
Display and format instructions
Structure of files and tables
Security and access rules
Triggers and operational rules
6
Introduction …. cont’d
Metadata
Data Item Value
Name Type Length Min Max Description
Course Char 7 Three digit depart-
ment reference
and 4 digit
Section Integer 3 001 900 Section number
7
Data management approaches
• Data management : keeping your data records
We have three approaches
• Manual Approach
• File-Based Approach
• Database Approach
Manual File Handling Systems
• The primitive and traditional way of information handling
• This may work well if the number of items to be stored is small.
• Includes intensive human labor
• Events and objects are written on files (paper)
• Each of the files containing various kinds of information is labeled and stored in one
or more cabinets
• The cabinets could be kept in safe places for security
8
Limitations of Manual File Handling
• Problem of Data Organization
• Problem of Efficiency
• Prone to error
• Difficult to update, retrieve, integrate
• You have the data but it is difficult to compile the
information
• Significant amount of duplication of data
• Cross referencing is difficult
9
File based Approach
• File based systems were an early attempt to
computerize the manual filing system.
• It is a decentralized computerized data handling method
i.e. to develop a program or a number of programs for
each different application.
• Since every application defines and manages its own
data, the system is subjected to serious data duplication
problem.
• File, in traditional file based approach, is a collection of
records which contains logically related data.
10
Limitations of File-Based systems
• Data Redundancy (Duplication of data)
• Same data is held by different programs
• Staffsalary(staffno, name, sex, salary)
• Staff(staffno,name,position,sex,dateofb,salary)
• Wasted space (Uncontrolled duplication of data)
• Separation and isolation of data: Each program maintains its own set of
data. Users of one program may be unaware of potentially useful data held
by other programs.
• Limited data sharing- No centralized control of data
• Data Inconsistency and confusion
• Data dependence: File structure is defined in the program code and is
dependent on the application programming language.
By Aliyan Aman 11
Limitations of File-Based systems .. Cont’d
12
Database Approach
• Codd proposed that database systems should present the user with a view
of data organized as tables called relations.
• Database is just a computerized record keeping system or a kind of
electronic filing cabinet.
• 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.
• Database is a collection of logically related data where these logically related
data comprises entities, attributes, relationships, and business rules of an
organization's information.
• Database contains a description of the data which called as “Metadata” or
“Data Dictionary” or “Systems Catalogue” or “Data about Data”.
13
Cont..
• Since a database contains information about the data
(metadata), it is called a self descriptive collection on integrated
records.
• The purpose of a database is to store information and to allow
users to retrieve and update that information on demand.
• Database is deigned once and used simultaneously by many
users.
• That is the separation of the data definition from the
application. Thus the application is not affected by changes
made in the data structure and file organization.
• Each database application will perform the combination of:
Creating database, Reading, Updating and Deleting data.
14
Cont…
• a single repository of data is maintained.
• What emerged were the database and database management systems
• Basic Database terminologies
• Enterprise: an organization like library, bank, university, etc.
• Entity: Person, place, thing, or event about which we wish to keep data
• Attribute (Field): Property of an entity. E.g. Name, age, telephone, grade, sex,
etc.
• Record: A logically connected set of one or more Attributes that describe a person,
place or thing. (Logically related data)
• File: A collection of related records. E.g. Student file
• Relationship: an association among entities (entity records)
• Query: question asked for database
15
Benefits of Database systems
• Data can be shared: two or more users can access and use.
• Improved data accessibility: By using structured query languages, the
users can easily access data without programming experience.
• Redundancy can be reduced: Isolated data is integrated in database.
• Quality data can be maintained: the different integrity constraints in
the database approach will maintain the quality leading to better
decision making.
• Inconsistency can be avoided: controlled data redundancy will avoid
inconsistency of the data in the database to some extent.
• Transaction support can be provided: basic demands of any
transaction support systems are implanted in a full scale DBMS.
16
Benefits of Database systems … cont’d
• Integrity can be maintained: Data at different applications will be integrated
together with additional constraints.
• Security measures can be enforced: The shared data can be secured by data
security mechanisms.
• Improved decision support: the database will provide information useful for
decision making
• Standards can be enforced: ways of using different data by users
• Less Labor: 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.
• Data Independence - Applications insulated from how data is structured and
stored
17
Limitations and risk of database approach
• Introduction of new professional and specialized personnel
• High cost to be incurred to develop and maintain the system
• Complex backup and recovery services from the users
perspective
• High impact on the system when failure occurs to the central
system
• Complex backup and recover services from the user’s
perspective.
• Reduced performance due to centralization and data
independency.
• High impact on the system when failure occurs to the central
system.
18
DBMS
19
DBMS … Cont’d
• Concurrency Control Services: access of database by different users
simultaneously
• Recovery Services: a mechanism for recovering from failure
• Authorization Services (Security): support the access authorization
• Support for Data Communication: support data transfer
• Integrity Services: rules about data and the change that took place on the
data, correctness and consistency of stored data
• Services to promote data independency between the data and the
application
• Utility services: sets of utility service facilities like
• Importing data
• Statistical analysis support
• Index reorganization
• Garbage collection
20
Some general functions of a DBMS:
21
DBMS Language
22
DBMS Language … Cont’d
We have two types of DMLs:-
Non-Procedural Manipulation Languages
That allows the user to state what data is needed rather than how it is
to be retrieved.
E.g. SQL
Procedural Data Manipulation Languages
That allows the user to tell the system what data is needed and
exactly how to retrieve the data;
23
DBMS Language … Cont’d
24
Components of DBMS
• DBMS have several components, each performing very significant tasks
in the database management system environment.
1. Software
• This is the set of programs used to control and manage the overall
database. This includes the DBMS software itself, the Operating
System, the network software being used to share the data among
users, and the application programs used to access data in the DBMS.
2. Hardware
• Consists of a set of physical electronic devices such as computers, I/O
devices, storage devices, etc., this provides the interface between
computers and the real world systems.
3. Data
• DBMS exists to collect, store, process and access data, the most
important component. The database contains both the actual or
operational data and the metadata.
25
Components of DBMS
4. Procedures
• These are the instructions and rules that assist on how to use the
DBMS, and in designing and running the database, using
documented procedures, to guide the users that operate and
manage it.
5. People
• This component includes all DBMS users. On the basis of primary
job functions, five types of users can be identified in a database
system:
• Systen administrator, database administrator, database designers,
system analysts and programmers, and end users.
26
Database Development Life Cycle
27
Database Development Life Cycle … Cont’d
28
Users and Actors of Database System
• Actors on the scene: The people whose jobs involve the day-to-day use of a large
database
• Workers behind the scene: Those who work to maintain the database system
environment, but who are not actively interested in the database itself.
29
Database Administrators
• In a database environment, the primary resource is the database itself
and the secondary resource is the DBMS and related software.
• Administering these resources is the responsibility of the Database
Administrator (DBA).
• The DBA is responsible for authorizing access to the database, for
coordinating and monitoring its use, and for acquiring software and
hardware resources as needed.
• The DBA is accountable for problems such as breach of security or
poor system response time.
• Involves in all steps of database development
30
• We can have further classifications of this role in big organizations having
huge amount of data and user requirement.
1. Data Administrator (DA): is responsible on management of data
resources.
• It involves in database planning, development, maintenance of
standards policies and procedures at the conceptual and logical design
phases.
2. Database Administrator (DBA): is more technically oriented role.
He/she is Responsible for the physical realization of the database.
It involves in physical design, implementation, security and integrity
control of the database.
31
Database Designer
• Database designers are responsible for identifying the data to be stored in
the database and for choosing appropriate structures to represent and store
this data.
• It is the responsibility of database designers to communicate with all
prospective database users, in order to understand their requirements, and to
come up with a design that meets these requirements.
• In many cases, the designers are on the staff of the DBA and may be assigned
other staff responsibilities after the database design is completed.
• The final database design must be capable of supporting the requirements of
all user groups.
• They identify and design the whole set of entities, relations, constraints, and
views.
32
End Users
• End users are the people whose jobs require access to the database for querying,
updating, and generating reports;
• The database primarily exists for their use. There are several categories of end
users:
• Casual end users:- occasionally access the database. They are typically middle
or high-level managers or other occasional browsers.
• Naive or parametric end users:- Their main job revolves around constantly
querying and updating the database, using standard types of queries and updates
called canned transactions that have been carefully programmed and tested.
• Bank tellers check account balances and post withdrawals and deposits
• Reservation clerks for airlines, hotels, and car rental companies check
availability for a given request and make reservations
33
End Users … Cont’d
• Sophisticated end users: Include engineers, scientists,
business analysts, and others who thoroughly familiarize
themselves with the facilities of the DBMS so as to
implement their applications to meet their complex
requirements.
• Stand-alone users: Maintain personal databases by using
ready made program packages that provide easy to use
menu or graphics based interfaces.
• An example is the user of a tax package that stores a
variety of personal financial data for tax purposes.
34
System Analysts and Application Programmers (Software Engineers)
• System analysts: Determine the requirements of end users,
especially naive and parametric end users, and develop
specifications for canned transactions that meet these
requirements.
• Application programmers implement these specifications as
programs; then they test, debug, document, and maintain these
canned transactions.
• Such analysts and programmers (nowadays called software
engineers) should be familiar with the full range of capabilities
provided by the DBMS to accomplish their tasks.
35
Workers behind the Scene
• These persons are typically not interested in the database itself.
These include:
• DBMS system designers and implementers:-are persons who
design and implement the DBMS modules and interfaces as a
software package.
• A DBMS is a complex software system that consists of many
components or modules, including modules for implementing the
catalog, query language, interface processors, data access,
concurrency control, recovery, and security.
• The DBMS must interface with other system software, such as
the operating system and compilers for various programming
languages
36
Workers behind the Scene … cont’d
• Tool developers: Include persons who design and implement
tools
• Tools are software packages that facilitate database system
design and use, and help improve performance.
• Tools are optional packages that are often purchased separately.
• They include packages for database design, performance
monitoring, natural language or graphical interfaces,
prototyping, simulation, and test data generation.
• Operators and maintenance personnel: are the system
administration personnel who are responsible for the actual
running and maintenance of the hardware and software
environment for the database system.
37
Some Common uses of Databases
In a university
• Containing information about a student, the course she/he is enrolled in, the
dormitory she/he has been given.
• Containing details of Staff who work at the university at personnel, payroll,
etc.
In a library
• There may be a database containing details of the books in the library and
details of the users,
• The database system handles activities such as
• Allowing a user to reserve a book
• Notifying when materials are overdue
38
Some Common uses of Databases … Cont’d
In travel agencies
• When you make inquiries about a travel, the travel agent may access databases
containing flight details
• Flight no., date, time of departure, time of arrival
Insurance
• When you wish to take out insurance, there is database containing
• Your personal details: name, address, age
• information on whether you drink or smoke,
• Your medical records to determine the cost of the insurance
Supermarkets
• When you buy goods from some supermarkets, a database will be accessed.
• The checkout assistant will run a barcode reader over the purchases.
39
LO2:Develop logical data model
Logical Database Design
•Is the process of constructing a model of the information used in
enterprise based on a specific data model. but independent of a particular
DBMS and other physical considerations.
•Logical Data Base Design is a process of modeling and capturing the end-
user views of an application domain and synthesis them into a data base
structure.
•Normalization is a logical data base design method.
•The basis for normalization is the functional dependencies among
attributes in a table.
40
Database Models
• A data model is a collection of tools or concepts for describing data, the
meaning of data, data relationships, and data constraints.
• is a collection of conceptual tools for describing data, data relationships,
data semantics, and consistency constraints.
• A model is a representation of real world objects and events and their
associations.
• A data model is independent of hardware or software constraints. Rather than
try to represent the data as a database would see it, the data model focuses on
representing the data as the user sees it in the "real world".
Uses of data model
The main purpose of Data Model is to represent the data in understandable
way.
Helps in the visual representation of data and enforces business rules,
regulatory compliances, and government policies on the data.
It serves as a bridge between the concepts that make up real-world events
and processes and the physical representation of those concepts in a
database.
Ensure consistency in naming conventions, default values, semantics,
security while ensuring quality of the data.
emphasizes on what data is needed and how it should be organized instead
of what operations need to be performed on the data.
Data Model is like architect's building plan which helps to build a
conceptual model and set the relationship between data items.
The primary goal of using data model are:
Ensures that all data objects required by the database are accurately
represented. Omission of data will lead to creation of faulty reports and
produce incorrect results.
A data model helps design the database at the conceptual, physical and
logical levels.
Data Model structure helps to define the relational tables, primary and
foreign keys and stored procedures.
It provides a clear picture of the base data and can be used by database
developers to create a physical database.
It is also helpful to identify missing and redundant data.
Though the initial creation of data model is labor and time consuming, in
the long run, it makes your IT infrastructure upgrade and maintenance
cheaper and faster.
Database Models … Cont’d
• Data model can be divided into four:
1. Hierarchical Model
2. Network Model
3. Object oriented Model
4. Relational data Model
Hierarchical Model
• Consists of an ordered set of trees in a parent child mode.
• A parent node can have more than one child node and a child node should
have only one parent
• Connection between child and its parent is called a Link.
• The simplest data model
• Record type is referred to as node or segment
• The top node is the root node
• The relationship between parent and child can be either 1-1 or 1-M
• To add new record type or relationship, the database must be redefined and
then stored in a new form.
Hierarchical Model… Cont’d
Hierarchical Model… Cont’d
Advantage of Hierarchical Model
• Good for tree type problem (e.g. Family Tree Problem)
• Language is simple; uses constructs like GET, GET UNIQUE, GET
NEXT, GET NEXT WITHIN PARENT etc.
Disadvantages of Hierarchical Model
• Addition, deletion, and search operations are very difficult.
• There is duplication of data.
• Navigational and procedural nature of processing
• Database is visualized as a linear arrangement of records
• Little scope for "query optimization"
Network Model
Compiled by Aliyan A. 55
Relation Model
• Developed by Dr. Edgar Frank Codd in 1970 (famous paper, 'A Relational
Model for Large Shared Data Banks')
• Terminologies originates from the branch of mathematics called set theory
and relation
• Can define more flexible and complex relationship
• Viewed as a collection of tables called “Relations” equivalent to collection
of record types
• Relation: Two dimensional table
• Stores information or data in the form of tables ( rows and columns)
• A row of the table is called tuple which is equivalent to record
• A column of a table is called attribute which is equivalent to fields
• Data value is the value of the Attribute
Relational Model … Cont’d
• 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
Relational Model … Cont’d
Relational Data model (also called the second generation data
model), describes entities and their relationships in the form of table
Compiled by Aliyan A. 61
Properties of Relational Databases … Cont’d
• Is the collection of tables
• Each entity in one table
• Attributes are fields (columns) in table
• Order of rows and columns is immaterial
• Entries with repeating groups are said to be un-
normalized
• Entries are single-valued
• Each column (field or attribute) has a distinct name
• All values in a column represent the same attribute and
have the same data format
Compiled by Aliyan A. 62
Building Blocks of the Relational Data Model
The building blocks of the relational data model are:
• Entities: real world physical or logical object
• Attributes: properties used to describe each Entity
or real world object.
• Relationship: the association between Entities
• Constraints: rules that should be obeyed while
manipulating the data.
Compiled by Aliyan A. 63
Entity
An Entity is a thing in real-world (an object with a physical existence or an
object with a conceptual existence).
person/employee, car, book, house, employee, etc are example of objects
with physical existence
A project, course, payment, department, etc are examples of objects with
object with a conceptual existence.
Entity can be roles, events, tangible things or concepts.
Each entity must have its own identity that distinguishes it from every other
entity, called unique identifier.
• Example: Each Student has a unique ID that distinguishes one from others.
• Generally in database terms, an entity is a table which is responsible for
storing records in the database.
• In E-R Diagram, an entity is represented by a rectangle.
Compiled by Aliyan A. 64
ENTITIES
• The ENTITIES (persons, places, things etc.) which the
organization has to deal with.
• 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.
Compiled by Aliyan A. 65
Types of entities
• Entity types that do not have key attributes of their own are called weak
entity types.
• In contrast, regular entity types that do have a key attribute are called
strong entity types.
• Entities belonging to a weak entity type are identified by being related to
specific entities from another entity type in combination with one of their
attribute values.
• A weak entity type normally has a partial key, which is the attribute that
can uniquely identify weak entities that are related to the same owner
entity.
• We call this other entity type the identifying or owner entity type, and we
call the relationship type that relates a weak entity type to its owner the
identifying relationship of the weak entity type.
Compiled by Aliyan A. 66
Types of entities cont…
• A weak entity type always has a total participation constraint
(existence dependency) with respect to its identifying
relationship because a weak entity cannot be identified
without an owner entity.
• However, not every existence dependency results in a weak
entity type.
• For example, a DRIVER_LICENSE entity cannot exist unless it is
related to a PERSON entity, even though it has its own key
(License_number) and hence is not a weak entity.
• In ER diagrams, both a weak entity type and its identifying
relationship are distinguished by surrounding their boxes and
diamonds with double lines.
• The partial key attribute is underlined with a dashed or dotted
line.
Compiled by Aliyan A. 67
ATTRIBUTES
• The ATTRIBUTES - the items of information which
characterize and describe these entities.
Compiled by Aliyan A. 69
Types of Attributes
1. Simple (atomic) Vs Composite Attributes
• Simple : contains a single value (not divided into sub parts)
• E.g. Age, gender
• Composite: Divided into sub parts (composed of other attributes)
• E.g. Name, address
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
• Multi-Valued: have more than one value
• E.g. Address, dependent-name
• Person may have several college degrees
Compiled by Aliyan A. 70
Types of Attributes … Cont’d
3. Stored Vs. Derived Attribute
• Stored : not possible to derive or compute E.g. Name, Address
• Derived: The value 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) , 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.
Default value - assumed value if no explicit value
Compiled by Aliyan A. 71
Understanding relationships
• is an association that exist b/n two or more participating entities.
• Related entities require setting of LINKS from one part of the database to
another.
• A relationship should be named by a word or phrase which explains its function
• 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.
• An important point about a relationship is how many entities participate in it.
Compiled by Aliyan A. 72
DEGREE of the relationship
• The number of entities participating in a relationship is called the DEGREE of
the relationship.
• The number of entity sets that are connected through the relationship in question
is called the degree of relationship.
• Unary/Recursive Relationship: Tuples/records of a Single entity are related
withy 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: Tuples from arbitrary number of entity sets are
participating in a relationship.
Compiled by Aliyan A. 73
DEGREE of the relationship cont..
manager
worker
Compiled by Aliyan A. 74
Ternary Relationship Name
proj_name
budget
end_date
start_date
end_date
Contract
number start_date
value
Compiled by Aliyan A. 75
N-Nary Relationship
Compiled by Aliyan A. 76
CARDINALITY of the relationship
• Is the number of instances participating or associated with
a single instance from another entity in a relationship.
• ONE-TO-ONE:one tuple of an entity is associated with only one
other entity tuple. , e.g. Building – Location.
• ONE-TO-MANY:one tuple can be associated with many other tuples,
but not the reverse. e.g. hospital – patient.
• MANY-TO-ONE: many tuples are associated with one
tuple but not the reverse. e.g. Employee - 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 . e.g. Author - Book.
Compiled by Aliyan A. 77
CARDINALITY of the relationship cont…
Compiled by Aliyan A. 78
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 be null
• Referential Integrity: If a foreign key exists in a relation, either
the foreign key value must match a candidate key in its home
relation or the foreign key value must be null foreign key to
primary key match-ups
• Enterprise Integrity: Additional rules specified by the users or
database administrators of a database are incorporated
Compiled by Aliyan A. 79
Key constraints
• If tuples are need to be unique in the database, and then we need to make
each tuple distinct. To do this we need to have relational keys.
• Super Key: an attribute or set of attributes that uniquely identifies a tuple
within a relation. An attribute or a combination of attribute that is used to
identify the records uniquely is known as Super Key. A table can have many
Super Keys. Examples of Super Keys:
• ID
• ID, Name
• ID, Address
• ID, Department_ID
• ID, Salary
• Name, Address
• Name, Address, Department_ID and so on.
• As any combination which can identify the records uniquely will be a Super
Key. Compiled by Aliyan A. 80
Candidate Key
• Is a super key such that no proper subset of that collection is a Super Key within
the relation. It can be defined as minimal Super Key or irreducible Super Key. In
other words an attribute or a combination of attribute that identifies the record
uniquely but none of its proper subsets can identify the records uniquely.
• Examples of Candidate Key: Code , Name, Address
• For above table we have only two Candidate Keys (i.e. Irreducible Super Key)
used to identify the records from the table uniquely.
• Code Key can identify the record uniquely and similarly combination of Name
and Address can identify the record uniquely, but neither Name nor Address can
be used to identify the records uniquely as it might be possible that we have two
employees with similar name or two employees from the same house.
• A candidate key has two properties:
1. Uniqueness
2. Irreducibility
• If a candidate key consists of more than one attribute it is called composite
key.
Compiled by Aliyan A. 81
Relational Constraints/Integrity Rules .. Cont’d
• Primary Key: the candidate key that is selected to identify tuples
uniquely within the relation.
• The entire set of attributes in a relation can be considered as a
primary case in a worst case.
• What information about these entities and relationships should we store in the
database?
Compiled by Aliyan A. 89
Graphical Representations in ER Diagramming .. Cont’d
• A derived attribute is indicated by a DOTTED LINE.
(……..)
Compiled by Aliyan A. 90
Graphical Representations in ER Diagramming .. Cont’d
Compiled by Aliyan A. 91
Graphical Representations in ER Diagramming .. Cont’d
Compiled by Aliyan A. 92
ER diagramming
• EXAMPLE2: Design an ER diagram for the following information.illustrate
the major rules in mapping ER to relational schema:
• Employee ,Department and Project information.
• Employee: Eid, Name,Salary,Tel.
• Department: Did, Dname, Dloc.
• Project: Pid, Pname, Pfund
Business rule: Employee works for department;
• where an employee might be assigned to manage a department.
• Employee might participate on different projects with in the
organization.
• An employee might as well be assigned to lead a project where the
starting and ending date of his/her project leadership and bonus will be
registered.
Compiled by Aliyan A. 93
Solution for example 2
Compiled by Aliyan A. 94
Assignment
• Build an ER Diagram for the following information:
A Personnel record management system will have the
following two basic data object categories with their
own features or properties. Employee will have an Id,
Name, DoB, Age, Tel and Department will have an Id,
Name, Location
Whenever an Employee is assigned in one
Department, the duration of his stay in the
respective department should be registered.
Compiled by Aliyan A. 95
Entity versus Attributes
• Consider designing a database of employees for an organization:
• Should address be an attribute of Employees or an entity (connected to
Employees by a relationship)?
• If we have several addresses per employee, address must be an
entity (attributes cannot be set-valued/multi valued)
• If the structure (city, Woreda, Kebele, etc) is important.
E.g. want to retrieve employees in a given city, address must be modeled
as an entity (attribute values are atomic)
• Cardinality on Relationship expresses the number of entity
occurrences/tuples associated with one occurrence/tuple of related entity.
Compiled by Aliyan A. 96
More on ER diagramming
• Example 3: Create a simple ER diagram for a STUDENT
database. What is the requirement of this database?
• ‘Student attends class. Each class is divided into one or more
sections. Each class will have its own specified subjects.
Students have to attend all the subjects of the class that he
attends’.
• Identify what are the entities?
• Identify corresponding attributes of each entity and their
types.
Compiled by Aliyan A. 97
Solution
STUDENT, CLASS, SECTION, SUBJECT are the entities.
Attributes of these entities are not specified here. But we know what
could be the entities of each of the entities. We can list them as below at
this point of time.
STUDENT CLASS SECTION SUBJECT
STUDENT_ID CLASS_ID SECTION_ID SUBJECT_ID
STUDENT_NAME CLASS_NAME SECTION_NAME SUBJECT_NAME
ADDRESS
DOB
AGE
CLASS_ID
SECTION_ID
Compiled by Aliyan A. 98
What are the relationships we have? ‘Attends’, ‘has section’, ‘have subjects’
and ‘studies subjects’ are the relations here.
With this knowledge of requirement, we can draw the ER diagram as below.
Compiled by Aliyan A. 99
Cont…
• Observe the diagram carefully. Did we miss or drew it correctly? Are we missing
anything on the diagram? Is it inferring correct requirement? What are our
observations?
• Age attribute can be derived from DOB. Hence, we have to draw dashed oval.
• Address is a composite attribute. We have to draw its sub attributes too. So that
we will be very clear about his address details.
• If we see the SECTION entity, by section id, will we be able get the section that
student attends? There is no relation mentioned between Student and Section.
But Section is mapped only with Class. What do we understand from this?
Section is a weak entity. Hence we have to represent it properly.
• If we look at ‘attends’ relationship between STUDENT and CLASS, we can have
‘Joining Date’ and ‘Total Number of Hours’ attributes. But it is an attribute of
relation. We have to show them in the diagram.
• Since each class is having different subjects and Students attends those subjects,
we can modify the relation ‘studies’ to ‘has’ relation on the relation ‘attends’.
Compiled by Aliyan A. 100
Now the diagram will change to reflect all above points.
Fig: Example ER Diagram with Strong Entities, Weak Entities, and Simple attribute, Composite Attribute,
Keys and Relationships etc. Is the above diagram is a complete diagram? No, we have not added the
cardinality and participation in the diagram. Compiled by Aliyan A. 101
Participation Constraints
• From the above diagram all the Students attend any one of the
class, but class can have only certain group of students. Hence
total participation of Students and partial participation of class in
‘Attends’ relation.
• All the class has section and all the section has class. Hence both
are total participation.
• All the Students study some of the subject’s specific for their class
and each class has only some group of subjects.
• Hence partial participation of both STUDENT and CLASS. Each
subject will be studied by some students and it will be part of
some class. Hence this also partial participation.
Compiled by Aliyan A. 102
Cardinalities of All the Relationship
• Each Student attends only one class at a time. Hence it is
a 1: 1 relation.
• Each class has one or more sections. Hence it can be
considered as 1: N relation.
• Each student attends many subjects and each class has
many subjects. Hence it is a 1: N relation.
• Note: If you look at STUDENT and CLASS relationship as
many Students attend one class, then it would be an M: 1
relation.
Compiled by Aliyan A. 103
Cont…
Example
•Double line between the entity set “Student” and relationship set “Enrolled in” signifies
total participation.
•It specifies that each student must be enrolled inA. at least one course.
Compiled by Aliyan 106
Total participation cont…
Participation of EMPLOYEE in “belongs to” relationship with
DEPARTMENT is total since every employee should belong to a department.
Example
•Single line between the entity set “Course” and relationship set “Enrolled in”
signifies partial participation.
•It specifies that there might exist some courses for which no enrollments are
made.
Compiled by Aliyan A. 108
Partial participation cont…
• Pitfalls of Normalization
• Requires data to see the problems
• May reduce performance of the system
• Is time consuming,
• Difficult to design and apply and
• Prone to human error
Since the type of Wine served depends on the type of Dinner, we say Wine is functionally
dependent on Dinner. Dinner Wine
Since both Wine type and Fork type are
determined by the Dinner type, we say Wine
is functionally dependent on Dinner and Fork
is functionally dependent on Dinner.
Dinner Wine
Dinner Fork
Compiled by Aliyan A. 167
Partial Dependency
• If an attribute which is not a member of the primary key is
dependent on some part of the primary key (if we have
composite primary key) then that attribute is partially
functionally dependent on the primary key.
• Let {A,B} is the Primary Key and C is no key attribute.
Then if {A,B} C and B C
Then C is partially functionally dependent on {A,B}
Transitive
Dependency
EMPLOYEE
BOOK
BOOK
BOOK
ORDER
PART
PART
STUDENT
Stud_ID Na me
101 Lennon
125 Jons on
STUDENT_COURSE
Composite
Primary Key
STUDENT
STUDENT
• Distribute the multi-valued attributes into different rows and identify a unique
identifier for the relation so that is can be said is a relation in relational database.
• This schema is in its 1NF since we don’t have any repeating groups or attributes
with multi-valued property. To convert it to a 2NF we need to remove all partial
dependencies of non key attributes on part of the primary key.
• {EmpID, ProjNo} EmpName, ProjName, ProjLoc, ProjFund, ProjMangID
• But in addition to this we have the following dependencies
EmpID EmpName
ProjNo ProjName, ProjLoc, ProjFund, ProjMangID
Compiled by Aliyan A. 203
Compiled by Aliyan A. 204
Second Normal form 2NF … Cont’d
• As we can see some non key attributes are partially dependent on some
part of the primary key.
• Thus these collections of attributes should be moved to a new relation.
• The primary key for this table is the composite key (PatientId, RelativeId).
Compiled by Aliyan A. 206
Second Normal form 2NF … Cont’d
• So, to determine if it satisfies 2NF, you have to find out if all other
fields in it depend fully on both PatientId and RelativeId; that
is,you need to decide whether the following conditions are true:
• (PatientId, RelativeId) Relationship and
• (PatientId, RelativeId) Patient_tel.
• However, on the dependencies in the patient table, only the
following are true:
• (PatientId, RelativeId) Relationship and
• (PatientId) Patient_tel.
Therefore; based on the above dependency the normalized relation will be divided into to
tables.
Compiled by Aliyan A. 207
Second Normal form 2NF … Cont’d
• This schema is in its 2NF since the primary key is a single attribute.
Compiled by Aliyan A. 210
Third Normal Form (3NF ) … Cont’d
Now, PK = empid
Thank you!!!!!