You are on page 1of 9

DATABASE MANAGEMENT SYSTE

NTRODUCTION TO DATABASE MANAGEMENT SYSTEMS 45


44
with the fields:
w e can form a
relation-WORKS-ON
S# Sname Status
omlarly,
Status
Pid City
Pr-id SUPPLIER
fields
And the third relation-PROJECTS with
Start-date
Pid
End-date overall transformation
That is,
t is now we can create tables in any DBMS.
SPJ
summary is:
ER-diagram is drawn

converted to PART PROJECT


Relations
Weight
implemented as
Pname Coor Jname
Tables using DEMS software (s) (i.e., SQL)
Fig. 1.29
between ER-models and Relational
Thus, we can summarize the one-to-one mappings Example 2 Consider the following CUSTOMER entity having composite attributes
models. also. Convert it to a table (or relation).

s.No. ER-model Relational Model


fname mname Iname
Entity type is converted to a relation (table)

to foreign key
t:1 or 1:N elationshiptype
M:N relationship type a relation and two foreign keys
cname
an attribute (or fields) Phone no.
Simpleattribute cid
S. Value sets domain
Key attribute primary key City

CUSTOMER
This is how an ER-model is converted directly to a Relational model. So, an ER-
diagram acts as a blueprint of the database. It allows a designer to communicate more Fig. 1.30
precisely. Solution. Since CUSTOMER is entity with composite attribute-cname. So, the rule
an
These conversions can also be done using CASE tools. followed isThe composite attributes are flattened out by creating a separate attribute
for each component attribute." So, in our table, we will have the following flattened
1.7 sOME SOLVED EXAMPLES attributes
We are in a position to solve some examples now. CUSTOMER (Cid, fname, mname, Iname, phone no, city)
Example 1. Consider the following suppliers-parts-projects database: Thus, we can say that a multi-valued attribute, M, of an entity, E, is represented by
to
a separate table EM. And that this table, EM, will have the attributes corresponding
SISt, SNAME, STATUS, CITY the primary key of E and an attribute corresponding to multi-valued attribute, M.
PP#, PNAME, COLOR, WEIGHT, CITY shown
JJ#, JNAME, CITY Example 3. Consider an ER diagram now that has a weakentity set-Paymentas
below:
SPJ(S, Pt, J#, QT)
Pay date Pay
emount
Where S: Infomation of Pay no.
suppliers Loan-no. Amount
Parts
J Projects
SPJ Supplied quantity LOAN
Loan
pay
PAYMENT
Draw it's ER-diagram? WEAK
STRONG
Solution. Using our rules, listed earlier we
get the following ER-diagrams: Fig. 1.31
DATABASE MANAGEMENT SYSTEMS
46 INTRODUCTION TO DATABASE MANAGEMENT SYSTEMSs 47
How will you transform (convert) this table into a Relation, KR
from the Example 7. An information system is to be designed for keeping the records of
primary key or discriminator
Solution. We create a new relation, R with oneattributes Universe cup cricket tournament. In all, there are teams from 10 countries participating
other of the STRONG entity-LOAN
WEAK entity-PAYMENT and all remaining in the toumament. Each country sends 15 players and 4 other members. For players,
That is, the runs he scores and the number of wickets taken (so far) are to be recorded. For
R(loan -no pay-no pay-date, pay-amt) set into non-players, the role (manager, coach etc.) and the number of years of experience in
Example 4. How will you convert a M: N (many-to-many) relationship a
that capacity are to be recorded. There are matches scheduled amongst the teams on
relation, R? several grounds on fixed dates. Each ground has a fixed seating capacity and a size.
Solution. The rule is "Create a table with columns for the primary keys of the two
For 38 matches, 11 referees have been assigned duties. Every match will have 3 referees
set."
participating entity sets and any descriptive attributes of the relationship working for it. The performance of every player in every match is to be recorded ina
and (E F, G) and hat
For example, Let R and R, be 2 relations. IfR, (A, B, C, D)a newR,relation R with the
terms of the runs he scored and the wickets he took. Draw an E-R model of the system.
R and R have M: N relationship type then we need to create Design table layouts fom E-R model.
attributes, R(A, E). (Pune University, BE (CSEIT)-3 yr, Dec. 98)
Example 5. Horw can you comoert two entities into a table which has1:M elationship hype? Solution.
Solution. 1: M (one-to-many) and M: 1 (many-to-one) relationship sets that have
total participation on the many side can be represented by adding an extra attribute to
Ref name
the many side, containing the primary key of the one side.
For example, say R and R are the two entities with M: 1 relationship type ie, Refid Country
field-1 Refree
fhield-1 field-2 held-2

R rel-type
K field-3
Country
Match
refree
Seating Day Date Date Day
capacity Team id
Fig. 1.32
Match Match Team
Here, instead of creating a table for 'rel-type Ground Match schedule
field of R, to R. (relationship), we can add an attribute/ ground
Example 6. A chemical or set of chemicals give rise to another chemical or set of Match id (P_countryD name) (P name
chemicals, when reacts under no condition or a set of conditions. P.id
sodium react to give Sodium Hydroxide Like, water and Mruns Match
Whereas CH, and Clh form chloromethaneand Hydrogen and no condition is required. detail Player Non-player
reactions possible and each reaction has towhen exposed to light. There are numerous
be given a reaction
and condition has to be given a code. Draw its number. Each chemical M_wickets P matches Team i d NP
Solution ER-diagram. Crunse wickets
COuntry
State
Chemcode Name Team i d Date

Color Fig. 1.34. EER Diagram


Chemical
Description of entities in E-R diagram:
1. Match (match id) primary key match id.
2. Ground entity set with attributes:
PRODUCE>
lgid. country, city, size, seating capacity
Condition KRESULTS Reaction-Type Primary key 8 id
attributes:
3. Referee entity set with
Ccode details (ref id, ref name, country)
R No
Primary key ref id
DATABASE MANAGEMENT SYSTEMs
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS 49
4. Team entity set with attributes (Teamid 5. Non-player Table:

Primary key Team id Team_id NP_id NP_name NP country NP exp NP Role


5. Player entity set with attributes:
1001 111 Gaikwad India Manage
P_id, Team_id, P_name, Page, P_country, 2001 112 Coach
P_wickets, P_runs, P_matches: Kapil India

Primary key - P_id, Team id) 6. Match Ground:


6. Non-player entity set with attributes:
role) id Gr_id Day Date
INp-id, Team i d , Np_name, Np_ country,
Primary key Np_id, Team id) 001 10L Monday 12/2/2012
Description of Relationship Sets in E-R Díagram Match entities.
002 20L Tuesday 13/3/2012
relates Ground and This
Match-ground is a relationship set that this relationship set are: 7. Match Referee:
relation is many-to-many. Attributes of

g id,mateh id} Referee and Match entities. This


id Ref i d
2. Match-referee is relationship set that relates
a
set are: 001 011
relation is many-to-many. Attributes of this relationship
001 021
(refid, match_id)
3. Match schedule is a relationship set that relates Team and Match entity sets. This
8. Match Schedule
is a many-to-many relationship. Attributes of this set are:
m_id team id mday m_date
tmatch id,team id, day, date]
4. Match-detail is a relationship set that relates match and player entities. This is a 001 1001 Monday 12/3/2012
many-to-many relationship with attributes 001 2001 Monday 12/3/2012
match id, p_id, m_runs, m_wickets, team_id). 9. Match Detail:
Tables for each set
1. Match Table: team id mwickets
mid P_id m_runs

01 1001 100 2
Mid 001
001 01 2001 57 0
001
002
Example 8. Assume you are requirements of a wholesale
to compose database
from different manufacturers (brands).
2. Ground Table: dealer for audio, video consumerequipment
credit to old
Customers are the various retail outlets (retailers). Wholeseller extends
You have to
8id Country Gr_city Size Customer and special discounts are offered to new customers (retailers).
Capacity with the scope restricted to
India generate an E-R model for the above DBMS application
101
Bombay 1000 20,000 details (queries on) of customers (retailers), products stocked
and their price discounts
201 Australia Melbourne 2000 15,000 (Pune University BE (CSETT) Dec. 97)
and credits offered etc.
3. Referee Table: Solution. Description of entities:
1. Consumer-equipment with attributes lequip id)
Refid Refname Refcountry 2. Audio-equipment with attributes la id, equip_id, brand)
011 XYZ 3. Video equipment with attribute {V_id, equip_id, brand)
021 PQR
England 4. Wholesale-dealer with attributes (dealer_id
India
4. Player Relation: 5. Customer with attributes (cid, cnamel
6. New with attributes (c_id, c_name, discount
Team id Player id Ply_age Ply_name Ply runs P_wick Ply match|
7. Old with attributes (c id, c name, credit}
1001 01 24 Sachin 8000 75 250
Description of relationships:
2001 01 34 Mark 6000
Cons-whole with attributes lequip_id, dealer)
220
Equip-cost with attributes lequip id, dealer, cust id, cust _name)
DATABASE MANAGEM

TSTEMs
MINTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
50 51

(Dealer
id Name
Equip id City
A AD M Mnam
Wholesale
dealer Act
Consumer Cons_whole address Actor Movie
equipment add movie

movie
Street
Equip_cost Dir
(Add_id Director
Audio Video Cust id address
equip equip
Customer Street City Name
Name
Brand Aid Vid Brand Fig. 1.36. E-R Diagram
that has a set of
Discount ISA Credit Example 10. Construct an E-R diagram for a car-insurance company
customers, each of whom owns one o r more cars. Each car
has associated with it zero
M toany number of recorded accidents. (Pune Universitv BE (CSEAT; 3 yr.,
Dec. 2002)
New Old Solution.

Fig. 1.35. E-R Diagram


Example 9. A movie studio wishes to institute a database to manage their files of
Cust idCust name City Model
movies, actors and directors, The following facts are relevant. Each actor has appeared
in many movies. Customer Car
Cust
Each director has directed many movies.
Each movie has had one director and one or more actors.
Each actor and director may have several addresses and telephone numbers Street Car
ldentify the entities and attributes. Draw E-R diagram. accid
(Pune University BE (CSE/IT) May 1994)
Solution. Description of entities and relationships:
1 Actor is an entity with atributes
la name, aid) Ad Accidents Street
2. Movie is an entity with attributes (m_id, a
namel
3. Director is an entity with attributes (d_id,
name ga
2 Date Day City
4. Act movie is a relationship with attributes
fa id, mid)
5. Dir Movie is a relationship with attributes (d_id, Fig. 1.37. E-R Diagram
m id) and
6. Dir add is a relationship with attributes (d_id, for a hospital with a set of patients
a
a_id Example 11. Construct an E-R diagram tests ane
7. Act add is a relationship with attributes
faid, add_id set of medical doctors. Associate with each patient a log of the various
8. Act BE (CSE/T; 3 yt, May 2001
address is an entity
set with attributes
(ad id, city, street) examination conducted. (Pune University
9. Dir address is an entity set with atributes
fadd_id, city, street!
DATABASE MANAGEMENT SYST
STEN INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS 53
52
and mumber of
Sotution 3. Catalogue entity set with attributes catalogueid, number of movies
name games
Primary key: catalogueid
Secakab O name Street 4. The movies and games entity sets which we get as a result of generalization of
catalogue entity set.
Attributes of movie entity set are:
Potent
Cuskmer movieid, movie title, movie_actor, movie_actress,
movie dir, number of copies, movie_type and charge-per-day.
Primary key: catalogueid, movie_id
Osteet Attributes of game entity set are: game charge, game_id, gamesystem.
Primary key: game id, catalogue_id.
Equipment entity set attribute is equipment_id
Primary key: equipmentid
Temp Log 6. VCR and Video Equipment are entity sets derived by generalization of Equipment
entity set
Attributes of VCR are: VCR_id, VCR_company, and VCR_ent.
Primary key: VCR_id, equipmernt_id
Fig. 1.38. ER Diagram Attributes of video equipment are
video rental busines
Eample 12 Videobec is the leading corporation in the growing
It has the largest number of stores and prides itself on having the most comprehensin
V_id, V_company and V_rent
Video
list of video movies and games. It also rents VCR and video cameras to its members A VCR
a convenience, it repairs video equipment, the actual work being contracted out to
Camera

number of repair shops who reap 80% of repair charges. Each of videobec's store is ra
by a manager and an assistant manager who are full-time employees. In addition, ead camera
storehires its own part-time help who are paid on an hourly basis. The membernhi
priviledge is extended to customers for a period of 1 year and is renewable unless Str
Employee
member is habitually tardy in retuming items borrowed. A member is allowed to re omp

upto 12 movies, 6 video games, 1 vCR and 1 video camera simultaneously. Movies an
8ames can be retumed to any store but VCR and video cameras have to be returmed Equipments SIore Catalogue
the store from which they were boowed. Members have access to the on-line catalogu
of titles and may reserve titles. A reserved title has to be
which the reservation is automatically cancelled. Itenm are
picked before 6 p.m, afte
VB
items are to be retumed before noon.
charged per day and borrowe store
Any late retum bears a charge of 1 additional day
A discount of 20% is awarded on week days for all items
rented and a total discoun Movie Games
of 33% is also given on movie
rentals on week days, when more than 3 titles a
borrowed at a time. Movies are held by Videobec in both VHS and
Beta format. The
Videcbel
catalogue of movies contains title of movie, producer, director, 2 leading actors
of movies, number of cassettes available and categone
charge per
contains the name of the game, game system and day.
The video games catalogat VB
multiple copies of same title charger per day. Videobec came ReP
copies of each title.A store that and
a store
would have been assigned any number
to has more copies will retum these at the end of each o
Videobec's head office which redistnbutes them to wee Repair
diagram. appropriate stores. Draw E shop
Solution. Description of Entities: Mem
Mem Member
1. Videobec is an
entity with attnbutes name, address, quip
cat

stores, number of movies, number of e-mail, phone no., number


number of games, number of mber of VCRS
cameras, numb
Reser
members and number of
repairs. vation
2. Store entity set with attributes store id,
number of Fig. 1.40. E-R Diagram
number of cameras, number of VCRs, number of games, numbero f movies
Primary key: store_id employees.
DATABASE MANAGEMENT SYSTR

INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS 55


7 Employee entity set attributes are emp_1d Example 14. Following information is maintained manually in a library.
Primary key: emp id
and ful-timne Books (Accession_number, name, authors, price, book type, publisher)
Employee set results in part-time
8 Generalization of
Attribute of theseentity sets are id, name, salary,
work Borrowers (membership_no, name, address, category, max no of books that can be
issued, Accession number of books borrowed)
9. Member entity set attributes are The following constraints are observed

member id,name, date, rem. G) Each book has unique accession_number.


Description of Relationship Sets: ) A book may have more than one author.
1. Reservation entity set having attributes: (iii) There may be more than one copy of a book.
that may be
movie id,memberid (iv) The category of borrower determines the max. number of books
2. Vbstore i s one-to-many relationship between Videobec and store. issued to borrower.
Atributes are store id. ldentify the entities, relationship and draw E-R diagram.
3. Vbrep- is one-to-many relationship between Videobec and repair shop. Provide for issue and return of book, fine calculation and claiming of an issued book.
4. Eq str is many-to-many relationshíp between Equipment and store with attribute
Solution.
equip id, store id.
5. Stremp is many-to-many relationship between store and emplyee with attribuk
store id and emp_id.
Authors
6. Str_cat is many-to-many relatíonship between store and catalogue with attribue
store id and cat id. Wnite
7. Mem equp is aggregation which relates eq str, relationship and member entit
with attributes num-mid,
equip_id,store id. Oay ret)
8. Mem_cat is aggregation which relates str_cat and member
entity. Fine Maxn
Attributes of this relationship set are store_id, cat_id, mem_id. o copies
Book 18sue

Example 13. An insurance agent sells insurance policies to clients. Policies can b Sta
of different types such as vehícle insurance, life
insurance, accident insurance e t
The agent collects monthly premiums on the
policies in the form of cheques
local banks. Appropriate attributes must be assumed for various entities
such as agens
vehicles, policy. Dayis
Draw an E-R model for above
system. Your E-R model should take advantage d
extended E-R notation where relevant.
Fine Studer
(Pune University BE (CSEIT); 3
Solution
yr., June 2000, 12 Marks Day ret

Name ISA
St ld

Agent
Bank Policies Borrowe
name
Fig. E-R Diagram for Ex. 14
medical record database system, given the
se Example 15.
following data
t is required to set-up

of birth, blood group


number, name, address data
identification
(Amount Life
Vehicle
Patients
their specialties.
Clients Accident name, address and
insurance Physician identification number,
insurance insurance
Data about patients visit to physician like the date of visit,
the medicine
the visit, result of those
each medicine, tests ordered at
Cid prescribed, the dose of
tests, temperature, blood pressure.
the database.
Fig. E-R Diagram for Ex. 13 Give an E-R diagram for
TABASE MANAGEMENT SYSTE NTRODUCTION TO DATABASE MANAGEMENT SYSTEMS 57
56 Solution.
Solution. Address) Name id) Name Address StreetBuildings
Name Address
Name Works
Id_no Post office for Postmen Designated Address
Address Specialists area

Patient
Physician

Delivers

(Name of
(Temp Date
Sender

Test Medicine Status Letters Name of


Receiver

Dose (Date_o Date o t


amval vegistration
Fig. E-R Diagram for Ex. 15 Fig. 1.44. E-R Diagram for Ex. 16
Example 16. A Post office has few postmen who go everyday to distribute letten Example 17. A university database contains information about professors and courses.
Every moming post office receives a large number of registered leters. The post ofie For each of thefollowing situation drawan ER diagram that describesit
Professors can teach the same course in several semesters, and only the most
intends to create a database to keep track of these letters.
recent such offerings need to be recorded.
Every letter has a sender, an origin post office from where it was sent, offering is
Professors can teach the same course in several semesters, and each
destination post office to which it is to be sent, a date of
registration, date to be recorded.
arrival at destination post office, receiver and a status. must teach some course.
Every professor
Every sender has a name and an address. Every professor teaches exactly one course.

Every receiver has a name and an address. Every professor teaches exactly one course and each course must be taught bby
one professor.
Every postman has a
designated area where he delivers letters teach certain jointly, but it is
Now suppose that team of professors can courses

The consists ofa set of streets under team can teach the course. Model this
are
the jurisdiction of the post office. possible that no one professor in a
sets and relationship sets if necessary.
Every street consists of a set of situation, introducing additional entity
buildings. Solution.
Every building has a number and may be a name. It Recent
one family. may be housing more tna 4 Professo offering
Course

The status of the letter can be not yet taken


for delivery,
not available, address not known, addressee did not delivered, addresse ach

(2 Profess0r pfe Course


to the new address of the addressee and sent accept the letter, redirected Oenng

to the sender.
Draw the E-R Diagram
() Professor Course
Teach

4) Professor Teach Course

Professor
(5) Professor
Database with Courses and Professors Information
Fig. 1.45 University
DATABASE MANAGEMENT SYST

58 INTRODDCTION TO DATABASE MANAGEMENT SVST


STEMS 59
information about
a university database,
Example 18. Considerthe following research area. Solution.
an age, a rank and a

Frofessors have an id, a name, starting date, and finish 4.


Projects have a project number, funding
a agency, a Courses
and a budget
Under-graduate students have an id, à name,
an age, course a

called as Principal Investigator. Direc Enrol


Eachproject is managed by one professor, work each project on.
One or more professors, called as Co-investigators,
must supervise their w
When graduate students work on a project, professor Research
a
Work Students
on the project. project
Graduate students can work on multiple projects in which case they will ha
Fig. 147. E-R Diagram of Team Controller
different supervisor for each one.
Departments have a department number, department name, and an office. Example 20. The people's bank offer five types of accounts: Loan, Checking
Departments have a professor known as HOD. Premium savings, Daily interest saving and Money market. It operates a number of
accounts. An account can be joint, ie, more than one client may be able to operate a
Design and draw the E-R Diagram
given account.
Solution.
Identify entities and draw E-R Diagram.
(Pune University BE (CSETT; 3 y, Dec. 2004)
Departmem
Solution.

Pof dept Chent -


Has Account

HOD Prof Daly


Money interest
market
Professor Managed Projocts saving
Loan Premium
savings
Superwise Checking
Work on Fig. 148. E-R Diagram of Five Bank Accounts

Example
The
21. Design a generalization-specialization hierarchy for motor-vehicle a

Students sales. company sells motorcycles, passenger cars, vans and buses. Justify the
placement of attributes at each level of hierarchy.
Fig. 146. E-R Diagram of
University Database (Pune University BE (CSE/TT; 3 yr, May 2003)
Example 19. Draw an E-R
diagram for a relational database Solution.
current term enrollment at that
Pune University with
instructors, 4000 courses and 30,000 students.
represents
following assertions. There are 2
Motor-Vehice
An instructor may teach none, one or more
courses). courses in a
An instructor must direct the given term (aver ISA
A course may have
research of at least ney
none, one or wo one student (average 2 stude Buses
A course may exist
even if no
student has
prerequisite
courses.
All courses are
taught by only one currently enrolled for that Passanger
The average enrollment in E-K
a
instructor Model cars Vans Model
A student must select at course is 30
least one
course per term. students.
(Pune Model Model
University BE (CSED; 3 20
yr, May Fig. 1.49. E-R Diagram of Motor Vehicle
DATABASE MANAGEMENT SYSTE
60 INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS 61
system:
ample 22. Draw for the following
the EER (ER) diagram Solution.
interactive, dynamic, secure
The project Nexus data mart' aims at providing an of
data warehouse of
an
Punj
& handling the (F-name M-name Lname F-name (M-name name (cvv No.
user
friendly'platform for reating, managing
part of the
National bank with the intend of reducing
workload on the
Databas
dN
Administrator and concurrently maintaining security at all ieves Name Type D.O NameCard NoType 0.0E
Nexus Data Mart is an efficient data handling system for establishing monitorin
and automating the data warehouse related tasks of companies. The software componen
of the system are developed using the shell programming features of UNIX (operatin ATM Data
and the hardware components adhere to the client-sever architecture.
System)
A farewell has been established to enhanced the security of the whole system. Th Credit Card Data
tasks performed by the system include extraction &e transformation of data available in th
or redundant informatia
form of raw data sheets, filtering of data to reduce
the quantity
within the system, entertaining requests of communication from the end-user an
F-name M-name name
establishing contact through a Mail Server and implementing an X-server to increase th
ease of operability of the system.
Name
At any state of the implementation of the ETL (Extraction-Transformation-Loading Acc. No Cust1D Email 1D
processes, sensitive data belonging to the organisation shal remain abstracted from t -Data
End-User thereby ensuring a high level of
security and sophistication for a naive usert
get hold of the functionality of the system.
Customer
The system's high efficiency Name Privilege
must be credited to the
power offered
by The Shell in FULL U-D
UND programming environment. The
scripts are concise yet extremely powerful, easy to
maintain and modify as per needs of the Sendmail
organisation being served. The main advantag
of programming within the UNIX environment is
the security that is offered
by the operating Processes Administrator
system at various levels. UNIX has three inherent provisions for
is provided by assigning protecting data. The firs
password and login names to authorised users At the file
level, high level of security is implemented only.
that are assigned to users by the
through read, write and execute permissions Server Sendmail
system administrator.
facility that allows us to export data in an unreadable Lastly, there is file encryption
format.
Nexus Data Mart is thus a robust Mail Server
system which is easy to maintain Bank
portable to all operating system that belong to the Unix and modify. Its Provides
Linus, AD, Fedora, CenOS, and Ubuntu etc. The
family such as Solaris, Red Hal
considerably by increasing its flexibility through system's's capabilities can be enhanced B-Address
Drogramming languages and increasing the rangetranslating the code into more than o B-Name B-Code
of formats in which data sheets can
fed into it. Draw its Enhanced ER
diagran
Protoco Mail Client Responder Type
Automatis
Fig. 1.50.

You might also like