Professional Documents
Culture Documents
I. Important terminologies
1.1. Database: Database is a collection of inter-related data which helps in
efficient retrieval, insertion, and deletion of data from database and organizes the
data in the form of tables, views, schemas, reports etc. For Example, university
database organizes the data about students, faculty, and admin staff etc. which
helps in efficient retrieval, insertion, and deletion of data from it.
1.2. Data Definition Language (DDL): which deals with database schemas and
descriptions, of how the data should reside in the database.
CREATE: to create a database and its objects like (table, index, views, store
procedure, function, and triggers)
ALTER: alters the structure of the existing database
DROP: delete objects from the database
TRUNCATE: remove all records from a table, including all spaces allocated for
the records are removed
COMMENT: add comments to the data dictionary
RENAME: rename an object
1.3. Data Manipulation Language (DML): which deals with data manipulation
and includes most common SQL statements such SELECT, INSERT, UPDATE,
DELETE, etc., and it is used to store, modify, retrieve, delete, and update data in a
database.
1
1.4. Database Management System: The software which is used to manage
database is called Database Management System (DBMS). For Example, MySQL,
Oracle etc. are popular commercial DBMS used in different applications. DBMS
allows users the following tasks:
2
Difficult Data Access: A user should know the exact location of file to access
data, so the process is very cumbersome and tedious. If user wants to search
student hostel allotment number of a student from 10000 unsorted students’
records, how difficult it can be.
No Backup and Recovery: File system does not incorporate any backup and
recovery of data if a file is lost or corrupted.
- DBMS 3-tier architecture divides the complete system into three inter-related but
independent modules as shown below:
Physical Level: At the physical level, the information about the location of
database objects in the data store is kept. Various users of DBMS are unaware
of the locations of these objects. In simple terms, physical level of a database
describes how the data is being stored in secondary storage devices like disks
and tapes and gives insights on additional storage details.
3
unaware of their storage. Also referred as logical schema, it describes what
kind of data is to be stored in the database.
4
Conceptual Design: The requirements of database are captured using high
level conceptual data model. For Example, the ER model is used for the
conceptual design of the database.
Logical Design: Logical Design represents data in the form of relational
model. ER diagram produced in the conceptual design phase is used to
convert the data into the Relational Model.
Physical Design: In physical design, data in relational model is implemented
using commercial DBMS like Oracle, DB2.
1.8. Advantages of DBMS
DBMS helps in efficient organization of data in database which has following
advantages over typical file system:
Minimized redundancy and data inconsistency: Data is normalized in DBMS
to minimize the redundancy which helps in keeping data consistent. For
Example, student information can be kept at one place in DBMS and accessed
by different users. This minimized redundancy is due to primary key and
foreign keys
Simplified Data Access: A user need only name of the relation not exact
location to access data, so the process is very simple.
Multiple data views: Different views of same data can be created to cater the
needs of different users. For Example, faculty salary information can be
hidden from student view of data but shown in admin view.
5
Data Security: Only authorized users are allowed to access the data in DBMS.
Also, data can be encrypted by DBMS which makes it secure.
Concurrent access to data: Data can be accessed concurrently by different
users at same time in DBMS.
Backup and Recovery mechanism: DBMS backup and recovery mechanism
helps to avoid data loss and data inconsistency in case of catastrophic failures.
1.9. DBMS functions
A Data Base Management System is a system software for easy, efficient, and
reliable data processing and management. It can be used for:
Creation of a database.
Retrieval of information from the database.
Updating the database.
Managing a database.
It provides us with the many functionalities and is more advantageous than the
traditional file system in many ways listed below:
6
inconsistent data states in both places. A DBMS uses data normalization to
avoid redundancy and duplicates.
Efficient memory management and indexing:
DBMS makes complex memory management easy to handle. In file systems,
files are indexed in place of objects, so query operations require entire file
scans whereas in a DBMS, object indexing takes place efficiently through
database schema based on any attribute of the data or a data-property. This
helps in fast retrieval of data based on the indexed attribute.
Concurrency control and transaction management:
Several applications allow user to simultaneously access data. This may lead
to inconsistency in data in case files are used. Consider two withdrawal
transactions X and Y in which an amount of 100 and 200 is withdrawn from
an account A initially containing 1000. Now since these transactions are
taking place simultaneously, different transactions may update the account
differently. X reads 1000, debits 100, updates the account A to 900, whereas
Y also reads 1000, debits 200, updates A to 800. In both cases account A has
wrong information. This results in data inconsistency. A DBMS provides
mechanisms to deal with this kind of data inconsistency while allowing users
to access data concurrently.
Access Control and ease in accessing data:
A DBMS can grant access to various users and determine which part and how
much of the data can they access from the database thus removing
redundancy. Otherwise in file system, separate files must be created for each
user containing the amount of data that they can access. Moreover, if a user
must extract specific data, then he needs a code/application to process that
task in case of file system, e.g., Suppose a manager needs a list of all
employees having salary greater than X. Then we need to write business logic
for the same in case data is stored in files. In case of DBMS, it provides easy
access of data through queries, (e.g., SELECT queries) and whole logic need
not be rewritten. Users can specify exactly what they want to extract out of the
data.
Integrity constraints: Data stored in databases must satisfy integrity
constraints. For example, consider a database schema consisting of the various
educational programs offered by a university such as Tech/M.Tech/B.Sc/M.Sc
etc. Then we have a schema of students enrolled in these programs. A DBMS
7
ensures that it is only out of one of the programs offered schema, that the
student is enrolled in, i.e. Not anything out of the blue. Hence, database
integrity is preserved. Apart from the above mentioned features a database
management also provides the following:
Security
1. 10. Data Abstraction and Data Independence
Database systems comprise complex data-structures. To make the system efficient
in terms of retrieval of data, and reduce complexity in terms of usability of users,
developers use abstraction i.e., hide irrelevant details from the users. This
approach simplifies database design.
Physical: This is the lowest level of data abstraction. It tells us how the data is
stored in memory. The access methods like sequential or random access and
file organization methods like B+ trees, hashing used for the same. Usability,
size of memory, and the number of times the records are factors that we need to
know while designing the database.
Suppose we need to store the details of an employee. Blocks of storage and the
amount of memory used for these purposes are kept hidden from the user.
Logical: This level comprises the information that is stored in the database in
the form of tables. It also stores the relationship among the data entities in
relatively simple structures. At this level, the information available to the user
at the view level is unknown.
We can store the various attributes of an employee and relationships, e.g., with
the manager can also be stored.
View: This is the highest level of abstraction. Only a part of the actual database
is viewed by the users. This level exists to ease the accessibility of the database
by an individual user. Users view data in the form of rows and columns. Tables
and relations are used to store data. Multiple views of the same database may
exist. Users can just view the data and interact with the database, storage and
implementation details are hidden from them.
8
View 1 View 2 View 3
Logical level
Physical level
The main purpose of data abstraction is to achieve data independence to save time
and cost required when the database is modified or altered.
(1). Physical level data independence: It refers to the characteristic of being able
to modify the physical schema without any alterations to the conceptual or logical
schema, done for optimization purposes, e.g., Conceptual structure of the database
would not be affected by any change in storage size of the database system server.
Changing from sequential to random access files is one such example. These
alterations or modifications to the physical structure may include:
Utilizing new storage devices.
Modifying data structures used for storage.
Altering indexes or using alternative file organization techniques etc.
(2). Logical level data independence: It refers characteristic of being able to
modify the logical schema without affecting the external schema or application
program. The user view of the data would not be affected by any changes to the
conceptual view of the data. These changes may include insertion or deletion of
attributes, altering table structures entities or relationships to the logical schema,
etc.
II. The entity relationship model
9
ER Model is used to model the logical view of the system from data perspective
which consists of these components:
2.1. Entity
An Entity may be an object with a physical existence – a particular person, car,
house, or employee – or it may be an object with a conceptual existence – a
company, a job, or a university course. There are many definitions and descriptions
of an entity. Here are a few; some are quite informal; some are very precise:
• An entity is a category of things that are important for a business, about which
information must be kept.
• An entity is something you can make a list of, is a class or type of things.
Two important aspects of an entity are that it has instances and that the
instances of the entity somehow are of interest to the business.
2.2. Attribute(s):
An attribute is a piece of information that in some way describes an entity. An
attribute is a property of the entity, a small detail about the entity. Attributes are
the properties which define the entity type. For example, StdID, StdName, Date
of birth, Address, Tel, Email are the attributes which defines entity type Student.
- Key Attribute
The attribute which uniquely identifies each entity in the entity set is called key
attribute. For example, StdID will be unique for each student.
- Composite Attribute
An attribute composed of many other attributes is called as composite attribute.
For example, Address attribute of student Entity type consists of Street, City,
10
State, and Country. In ER diagram, composite attribute is represented by an oval
comprising of ovals.
- Multivalued Attribute
An attribute consisting of more than one value for a given entity. For example,
Phone_No (can be more than one for a given student). In ER diagram, multivalued
attribute is represented by double oval.
- Derived Attribute
An attribute which can be derived from other attributes of the entity type is
known as derived attribute. (e.g., Age can be derived from DOB).
The complete entity type Student with its attributes can be represented as:
2.3. Instance
Entity has instances and that the instances of the entity somehow are of interest to
the business. It is the particular information about object in real world
2.4. Entity type
11
Group of attributes that depict to entity make entity type. All objects in natural
world become entity must have the same entity type
Example:
Objects: The people who work in Moonlight Coffee shop (like Mr. John, Ms. Jill
etc.)
Entity EMPLOYEE
2.5. Relationships
Present something of significance to the business
Express how entities are mutually related
Always exist between two entities (or one entity twice)
Always have two perspectives
Are named at both 2 ends
Drawn by line with symbol at both 2 ends
12
A particular relationship can be worded in many ways: An EMPLOYEE has a JOB,
or an EMPLOYEE performs a JOB, or an EMPLOYEE holds a JOB
Based on what you know about instances of the entities, you can decide on four
questions:
(1). Must every employee have a job? (yes)
In other words, is this a MANDATORY or OPTIONAL relationship for an employee?
(2). Can employees have one job? (yes)
Can confirm that employee has only one job, and
(3). Must every job be done by an employee? (no)
In other words, is this a MANDATORY or OPTIONAL relationship for a job?
(4). Can a job be done by more than one employee? (yes)
Can confirm that JOB has many employees do
Relationship Representation
Relationships are represented by a line, connecting the entities. The name of the
relationship, from either perspective, is printed near the starting point of the
13
relationship line.
The shape of the end of the relationship line represents the degree of the
relationship.
This is either one or many. One means exactly one; many means one or more.
In the above example, it is assumed that JOBS are held by one or more
EMPLOYEES.
This is shown by the tripod (or crowsfoot), at EMPLOYEE.
An EMPLOYEE, on the other hand, is assumed here to have exactly one JOB. This
is represented by the single line at JOB.
In the above example, it is assumed that JOBS are held by one or more
EMPLOYEES.
This is shown by the tripod (or crowsfoot), at EMPLOYEE.
An EMPLOYEE, on the other hand, is assumed here to have exactly one JOB. This
is represented by the single line at JOB.
There are four compositions as:
have
be held
have
be held
have
be held
14
have
be held
ATTRIBUTE
15
RELATIONSHIP
Relationship 1:1
Relationship m:m
The various types of m:m relationships are common in a first version of an ER Model.
In later stages of the model most m:m relationships, and possibly all, will disappear.
DRIVER CAR
CAR DRIVER
16
This type of relationship must normalized into 1:m or m:1, by add more
intermediary entity
17
CASE STUDY
18
You may notice that the cities in the weather forecast are not printed in a random
order. The German cities (Bremen, Berlin and Munchen) are grouped together, just
as the French cities are. Moreover, the cities are not ordered alphabetically by name
but seem to be ordered North-South. Apparently, this report “knows” something to
facilitate the grouping and sorting. This could be:
• Country of the city
• Geographical position of the city
and maybe even
• Geographical position of the country
Try to identify which of the above types of information is probably an entity, which
is an attribute, and which is a relationship.
City and Country are easy. These are entities, both with, at least, attribute Name and
Geographical Position. Weather Type could also be an entity as there is an attribute
available: Icon. For the same reason there could be an entity Wind Direction. Now,
where does this leave the temperatures and forecast date? These cannot be attributes
of city as the forecast date is not single value for a city: there can be many forecast
dates for a city. This is how you discover that there is still one entity missing, such
as Forecast, with attributes Date, Minimum and Maximum Temperature, Wind
Force. There are likely to be relationships between:
• COUNTRY and CITY
• CITY and FORECAST
19
• FORECAST and WEATHER TYPE
• FORECAST and WIND DIRECTION.
In this entity relationship diagram some assumptions are made about the
relationships:
• Every FORECAST must be about one CITY, and
not all CITIES must be in a FORECAST- but may be in many
• Every CITY is located in a COUNTRY, and every COUNTRY has one or
more CITIES
• A FORECAST must not always contain a WEATHER TYPE, and
not all WEATHER TYPES are in a FORECAST—but may be in many
• A FORECAST must not always contain a WIND DIRECTION, and
not all WIND DIRECTIONS are in a FORECAST—but may be in many
The rationale behind these assumptions is that we consider an incomplete
FORECAST still to be a FORECAST, unless we do not know the date or the
CITY the FORECAST refers to.
20
EXERCISES
2. Find the attributes appropriate to each entity, then draw a line between the attribute
and the entity or entities it describes.
3. List which of the following concepts you think is an Entity, Attribute, or Instance. If you
mark one as an entity, then give an example instance. If you mark one as an attribute or
instance, give an entity. For the last three rows, find a concept that fits.
21
4. Make a list of about 15 different entities that you think are important for
Moonlight Coffees. Use your imagination and common sense and, of course, use
what you find in the summary that is printed below.
5. Use the information from the receipt and make a list of entities and attributes.
6. Use the schedule that is used in one of the shops in Amsterdam as a basis for an entity
relationship model. The schedule shows, for example, that in the week of 12 to 18 October
Annet B is scheduled for the first shift on Monday, Friday, and Saturday.
22
7. Analyze the example page from Ralph’s famous Raving Recipes book and list as
many different types of information that you can find that seem important.
23
9. Choose entities, attributes and relationship for templates follow
24
10. Give the ENTITIES as follow:
READER BOOK
FACULT MAJOR
Y
a). Find attributes and make relationships for entities
b). Normalize relationship if necessary
25