Vous êtes sur la page 1sur 52

Lesson # 2

DATABASE CLASS NOTES

Database Design

Entity-relationship modeling with data (data modeling with EUR UML)

• Unal Yarımağan, "Database Systems", Academic Press, 2010

• ELmasre of Navathe, "Fundamentals of Database Systems", 5th Edition, Addison Wesley,


2008

• Teorey Toby, Sam Lightsto, Tom Nadeau, HV Jagadish "DB Modeling & Design, Logical
Design", 5th Edition, Morgan Kaufmann, 2011
Overview

• The general scheme for database design process

• Basic concepts
• Assets, Asset set and qualifications, Communication, Communication set of limitations
relations and relations types, role definitions

• key qualifications

• Weak Entity Sets

• Helpful Concepts
• Generalization

• Clustering, Composition

• An exemplary VT (COMPANY database)


• Examples of the data model and UML
VT Design Process

• VT design User Data-flow, sequence


diagrams or scenarios
• Data modeling
• Data engineering, related IT
expertise
• Application design
• design flow and interface
program
ER
• about software engineering
VT Design Process
VT Design
• Collection and analysis of requirements
(Requirements collection and analysis)
• VT Designer, talks with prospective database users to
understand data requirements and documented (interview)
makes

• Output: Data requirements


• functional requirements for the application ( Functional
requirements)
VT Design

• Conceptual scheme
• Conceptual design
• Data requirements annotated
• Detailed description of the types of entities (entity types)

• Relations detailed description (relationships)


• Restrictions detailed description (constraints)
• Top-level data model performs conversion of the data model
(Transformed data from high-level implementation of the data
model into model)
VT Design

• The logical design or data model mapping


(data model mapping)
• Result database schema is a data model of implementation of
the DBMS

• Physical design phase


• Internal storage structures, file Organizations, indexes,
access paths, and physical design parameters for the
database files Unspecified
Entity-Relationship (Entity-Relationship ER) Model

• ER data model definitions:


• Assets (Entities)
• Relationship (Relationships)
• Attributes (Attributes)

• UML diagrams ( UML notation)


• My Sunglasses in the development methodology uses.
• UML object corresponds to the presence in the ER.
• There are three parts of the UML object: name, attributes and
operations.

8
Asset / Communication sets

• There is every object that can be distinguished from others and


presence It called. A cluster of similar assets set of assets It called.

• of assets qualities has. entities and attributes are distinguished from


each other.
• EMPLOYEE (WORKER)
• John Smith, Research, productx
• a value of each character, that is a cluster containing all of the feasible values ​( domain
) has. The type attribute value range of the format are covered.

• between two or more entities «incident» define for grip relation It


called. If a similar set of equations of the same type A set of equations

The statement said.


• STUDENTS TAKE LESSON if
the relationship between STUDENT COURSES
Basic building blocks: existence, relations
Composite
attribute

key

key

Multivalued attr.

STUDENT LESSON
R

N N

three instances, the entity in the entity set for


CR CR 10
Communication Cluster limitations
Communication name ( relationship name): an appropriate name manade
presence in Correlation ( Participating entity types): 2 or more, same or
between different assets
The degree of correlation ( degree of a relationship): 2,3, ...
Staff numbers, which is escape-kaçlık ( cardinality ratio): 1-1, 1-N, N-1, N, N

ROLE identification: There is a correlation of assets in defining the roles of the


correlation function. It's open, it must be specified in cases where it's unclear.

11th
ER notations
There is addiction ( existence dependency):
• each a 'b' presence in the entity set B, if necessary, in the presence of a set of 'a'
must establish the existence of a relationship, "B assets are set to be dependent
on a set of assets» is called. primary entity A, B are called secondary entity.

• (Total / partial Participation)

ER: N N
to reader B
a
b

13
Key and Strong / Weak Entity Sets
• Entity / entities in equation set / group relation to the qualities or
characteristics used to distinguish from each other
key It called.
• Super key ( SuperKey): All switches are super key.
• Candidate key ( candidate key): BA An entity / relationship set of the 'K' key to any
self-subset super super key, if not the 'K' that entity / relationship set of candidates will
be key. (In other words, «a candidate key" = "minimal super key»)

• It can not be found in a key set of assets ( though not together all the key
attributes) This entity set
«Weak set of assets» It called. Key to the set of assets that «strong set of assets» the
statement said.
• Weak entity set, with a strong presence or N-1 type set 1-1
There are not dependent It must establish a relationship.

• The weak entity set, distinguishing quality In order to know the entities that are connected to the same
strong asset (s) - MOMENT It needs to be defined.
15
Examples of weak entity set

one N
HIGH SCHOOL reader
STUDENT
name
öğrno

Grand total
satışno
the satışform
history

one

ss

N Line
LineNum
Identifying key
keys in Relation:
• NN set of key relationships is the key to all of the entities in the
cluster correlation.
• 1-N N-side switch of the correlation set of correlation values
​in the key.
• The key switch of any of one to one correlation set may be a
set of assets.
The key to the weak entity set , There is a strong correlation cluster in
the presence (s) is + per sini moment.

•According to this; Identify the key relationship in the


previous example.

17
ER-correlation samples multigrade
WORKING CPM PROJECT

MACHINE

• In the above equation 3x:


• Relations between the two entities, 3. can not be expressed independently from the asset.

18
ER-correlation samples multigrade
ER-correlation samples multigrade

• Which one conveys more information?

(S, j, p) ≠ (h, p) (j, p) (p, j)

One more step further: If we do not want to use


weak entity type, how to design?
EUR-Generalization ( «ISA», «Do not belong» correlation)
ER: (disjoint, total) • Participation restriction:
weight
gnome • Compulsory
SHIP
• selective

• Exception restrictions:

D • OR
• AND

CRUISE SHIP CARGO SHIP • 4 different constraints defined, can be used


yolcusayı of the kalitesınıf according to need.
Load the yüktür
Capacity • Supertype entity qualifications / key is valid in
the presence of subtype.

ER: (disjoint, partial) ER: (overlap, total)

21
Clustering ( aggregation, "part of" relation)
• «Has a", "has / have been» relation
• 'Cluster' with 'parts' used for correlation between.
• Part relegated to the "existence dependent" going the composition. (Used in UML)

• Supertype in the generalization asset qualifications / key, which was applicable in the presence of subtype.
"Part of" if their relationship, moving to the nature of the assets in the asset type in all parts Type It is not
possible.

22
Modeling with UML
UML generalization UML constructs composition / aggregation constructs

composition: parts can not be found alone, they do


not express a meaning. Part is dependent on the
existing cluster.
aggregation: pieces, they express a meaning on their
own. For example, if the delete Teacher Course may be
available.
UML n- ary relationship UML in a primary key
Examples of assets and Relations with UML

of
CAR
STUDENT LESSON
Registration number BA
No. Make # Name and # Name of

Model Year surname of the 0 .. * loans


0 .. *
Color License CNS doğumt language

Plate => Notes taken

to B
one..* 0 .. *

=> EU

CHAPTER STUDENT
1..1 0 .. *

=> Read

26
Example (UML)
MALE WOMAN
0..1 0..1
=> Married

to B
1..6 0..50

=> EU

TEACHER upper 1..1 => Manage it


LESSON
RECORD
STAFF
0 .. *

subordinate
STUDENT

of

STUDENT LESSON

# Name and # Name of

surname of the 0 .. * loans


0 .. *
CNS doğumt language

=> Notes taken 27


Example (UML)

HIGH SCHOOL STUDENTS öğrno MOMENT


1..1 0 .. *
Lisenok BA
=> Read
lisea was Name and
sehr surname

• The key to what a person can receive a set of correlation again in the same course
would be different in the following example?

PEOPLE kişino BA COURSE


0 .. * 0 .. *
kno BA
=> Solids
Name and woman
surname is k

years of
success
SHIP Example (UML)
gnome BA
weight

YOLCUGEMİS YÜKGEMİ of the


Staff PNO BA
kalitesınıf of the IR yüktür of
0 .. *
yolcusayı yükkapasite
pAT

akdb anon {Necessarily OR}


BA 1..1
name
kurtarih
akdp titles of idarip
0..1 branches training
mission

{Necessarily OR}

0..1

Kadrod is yarızamanl of the Foreign

staffed sözleşmet is language of the

aylıkmaas dersbaşınaüc country 29


UML composition

Room No MOMENT

one..* 1..1 Building BnO

<== located BA

0..1

0 .. *

Staff PNO BA
1..1
one..* Part BnO BA

=> Calışır
Example 1: COMPANY Database
• We need to define a database schema design based on The Following (simplified) requirements
of the COMPANY Database:
• The company is organized into departments . Each department has a name, number and an
employee wHO manages the department. We keep track of the start date of the department
manager. A department may have several locations.

• Each department controls A number of projects . Each project has a unique name, unique
number and is located at a single location.
• We store each EMPLOYEE's social security number, address, salary, and birthdate.

• Each employee works for one department but may work on several projects.

• We keep track of the number of hours per week that an employee currently works on
each project.
• We also keep track of the direct supervisor of each employee.
• Each employee may have A number of dependents .
• For each dependent, we keep track of their name, sex, birthdate, and relationship to the
employee.
Initial Design of DB COMPANY
• Based on the requirements, we can identify four initial entity types in the COMPANY database:

• DEPARTMENT, PROJECT, EMPLOYEE and DEPENDENT


• The initial attributes shown are derived from the requirements description

DEPARTMENT PROJECT EMPLOYEE Ssn BA DEPENDENT name


number BA birthdate
number BA
name name location fname lname birthdate relationships
manager controllingdept department supervisor dependstoemp
managerstartdat to salary
locations worksonprojects
adresse
After the initial design improvements-1
• If pointing to another entity existing qualifications:

• Quality • Communication must become transformation.

• If you can get very value of existing qualifications:


• Quality • Assets must be set into rotation.
• If only one set of existing assets and attributes with a correlation
exists:
• Entity set • It should be transformed into nature.

• between entity sets " generalization" It must be done. The


above-bottom (top-down), aşağıdanyukarı A (bottom-up)
approach should be used.
• The degree of correlation should be re-evaluated, if necessary " clustering
" with structures should be used more hungry.
After the initial design improvements-2:
Removal of excess
• If a relationship is not a waste of time information extracted from the diagram, this
correlation of extra / unnecessary (redundant) decided that would be given. In general, it
is in my control loop diagram. Cevrim is likely to have an extra equations in it.

• The following example is being followed by the introduction of a section notes. If you entered a note
(GRADE), while for a PROF veriliyos SECTION SECTION and then by A; "Assigns" the relationship is going
to be needed? Of course, "will" Becoming.
COMPANY DBU (continued)
• In the refined design, some attributes from the initial entity types are refined into relationships:

• Manager of DEPARTMENT -> Manages


• Works_o of the EMPLOYEE -> WORKS_O's
• Department of EMPLOYEE -> WORKS_F is
• controlling_department of PROJECT • CONTROLS
• Supervisor of EMPLOYEE • the SUPERVISION
• Dependent_n renovation of DEPENDENT • DEPENDENTS_OF

• In general, more than one type of relationship can exist between the same Participating entity types
(types Manages and WORKS_F area distinct relationship between EMPLOYEE and DEPARTMENT
(Different Meanings and different relationship instances.)

35
COMPANY DB UML diagram
EMPLOYEE DEPARTMENT

1..1
one..* ==> works for
0..1

0 .. *
==> supervises

0..1
==> manages
1..1 1..1

one..*

1..1
0 .. * one..* startDate LOCATION
==> unique

surroundings BA

0 .. *

0 .. * PROJECT

DEPENDENT
hours one..*

36
COMPANY DB diagram

Recursive
relationship
Example-2 (ER, UML)
• Cities, countries and design a database showing rivers.

City Country
City R Country

N
one..* 1..1 one..*
1 N

0 .. *
M
River
River

• If we want to keep the river which passes through the city?

City R Country
1 City one..* 1..1
N Country

one..*
N S River
M 0 .. * River
Example 3
Part-employee data involving the departments and personnel information on a company
Think the base.
• Each chapter numerous staff Every staff member has and is subject to a maximum of one section.

• only an administrator of a section ( necessarily) has. Accordingly the following conditions independently
Your answer ...
• The manager of a chapter, but it can be connected to a personnel department, how an ER model
can be drawn?

0 .. *
1..1 ==> with
B PA

My manager?

• If the manager can be a part of any staff, how an ER model can be drawn?

0 .. *
1..1 ==> with
B PA

0..1 <== manages 1..1


Example 4 SALES FORM

History:
satışno: 12 11/06/2009

Unit
Fie t
LineNum Parr ç anon Parr ç I ais Definition Quantity Total
Sports, basketbaIIs
one 23 645 shoes l one 110 110

2nd 12 674 shirts classic style 2nd 80 160

3 . . . . . .

geneltopl
aM: 880

The above example shows the contents of a sale involving sales information form. corresponding
database, SALES, PARTS AND LINE It consists of 3 sets including asset. (The same can be repeated in different
parts parçanol line.)
This set of assets, properties and draw the ER diagram illustrating the relationships between them.

PART PNO BA
SALES

name

price

definition
1..1
0..1 Grand total and
the satırtoplamfiyat
0 .. * properties derived from
LINE nature. Writing in the
0 .. * conceptual design
quantity
becomes.
Example 5
• Among the teams with multiple players, it asked to be kept information about games
involving two teams. ( Players can have up to a team member. )

• in which every game involving teams (which team is which guest host) and kept
information such as the date and outcome of the game.
• Every game in which players get the information that is being followed for the team.

N one

player
team
belonging to

one
play one
score home

guest
score
NMR N
N
game

results

history PK
Example 6

• processing time of transactions on a bank account ( day, hour) transaction amount and type of
information following the event tutuluyor.b diagram:

Note: day, hour


one N amounts
partial key is going.
account belonging
belonging to
to
operation
operation
such
hours Different types of accounts and transactions can be the

same amount in the same time !!!


day GS

• The above solution treatment in the same time on the same account Failure to
the case is valid. When he raised this condition, the design process should keep the time as the
system time;

one N Note: days, hours,


amounts
seconds partial key is
account belonging
belonging to
to
operation
operation going.
such
hours

the same in different accounts second It may be the same


day GSS second types and amounts of transactions !!!
FLIGHT RESERVATION SYSTEM

• Each is Identified by a flight FLIGHT NUMBER, and Consists of one or more flıght_legs with
leg_numbers 1, 2, 3, etc.
• Each leg has scheduled arrival and departure times and airports, and has many
leg_ınstances - one for each DATE on which the flight travels. FARES are kept for each
flight.
• For each leg instance, seat_reservatıons are kept, as is the AIRPLANE used in the leg, and
the actual arrival and departure times and airports.

• Identified by the AIRPLANE is an AIRPLANE_ID, and is of a particular AIRPLANE_TYP


to.
• CAN_LAND aırplane_types relates to the airports in which they can land.

• AIRPORT is Identified by an AIRPORT_CODE.


Example 7: Figure 3.17 ELMASRI / Navathe book
Example 8
• Candidates talks with the company and we want to track the position was offered the job.

• Candidates can make a company's negotiations with multiple sections may take different positions and proposals from each department;
But you can get an offer from one position section.

• Offered salary of the position, a number of features such as more features are required to be kept ..

• On the day of the interview (year / month / day) is tutluy information. interviews with the same section, but can be a different day.

• Both candidates names must be unique in company names may assume that the system ..

• information is not held on a section.

position name
name
name N N
COMPANY
CANDIDATE interview CHAPTER
one
Date (dd) N made

name name
CANDIDATE
one interview one COMPANY

N name
Date (dd)
POSITION
IT INTERVIEW salary
one
chapter ...... 45
N bid
Example 9 (generalization)

• ER diagram ISA (SOLE) equation


• Participation is mandatory with a double line, not necessarily with the tekçizg
• Exception, OR (disjoint) The round of D with, AND ( notdisjoint) The
round of she is eidliy with expression. 46
Example 10 (generalization)

47
Example 11 (generalization)

48
Example 12: computer sales VT

N
software
one
one

computer
one İşl ist.
D MD b N
laptop desktop
must

dH
by
one
N

N MN
dH
equipment
peripherals
N1
D
D
memory video
keyboard monitor
the seeskart
mouse

You can select the appropriate qualifications ...


Example 13: Large DB design example
Example 13 (continued)
ANNEX (Activity diagrams)

Vous aimerez peut-être aussi