49
DATABASE ANALYSIS Chandra S. Amaravadi 1

DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

Embed Size (px)

Citation preview

Page 1: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

DATABASE

ANALYSIS

Chandra S. Amaravadi

1

Page 2: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

IN REQUIREMENTS ANALYSIS..

Overview of database analysis (requirements)

User views

Integrity constraints

Steps in database analysis

The ER model

Guidelines and examples

ER Additional semantics

2

Page 3: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

OVERVIEW OF

DATABASE ANALYSIS

3

Page 4: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

THE DEVELOPMENT CYCLE

Planning

Analysis (Requirements definition)

Design (Logical & Physical)

Implementation

Maintenance

4

The database development cycle consists of:

Page 5: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

DATABASE ANALYSISDatabase Analysis is the stage of the development cycle that is concerned with identifying and modelling the data requirements of the organization.

Primary database analysis takes place duringthis stage

5

Page 6: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

INFORMATION COLLECTED DURING RD

Information regarding data structure (from Views)

Information regarding rules/constraints e.g. weight limit

6

Two types of information are gathered:

Page 7: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

IDENTIFYING DATA STRUCTURE

Receipts

Forms

Reports and memos

Screen displays

Schedules etc.

A view is a user’s representation of data (also the wayit is presented to them):

7

Information identified:

Eclasses

Attributes

Rules if any

Page 8: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

AN EXAMPLE OF A VIEW

QUOTATION

Qty Description Price

Quote no: A61-45

Date: June 15,’12

8

Page 9: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

IDENTIFYING CONSTRAINTS

INTEGRITY CONSTRAINTS

Domain

Business constraints

Database constraints

Entity integrity

referential integrity

Are rules to preserve integrity of the database

9

Page 10: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

EXAMPLES OF CONSTRAINTS

DOMAIN CONSTRAINTSConstraints on allowable value of an attr.

e.g. E_name is alphabetic, E_address is alphanumeric

ENTITY & REFERENTIAL INTEGRITY

Primary key; Pkey <> Null

Referential integrity; values of cross-reference keys in different tables must match.

BUSINESS CONSTRAINTSRules concerning data: customers, purchases etc.

e.g. credit limit > $4,000, enrollment limit for course

DATABASE CONSTRAINTS:

10

Page 11: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

STEPS IN DATABASE ANALYSIS (FYI)

The different steps in database analysis are:

1. Define scope (from planning stage)

2. Select methodology (ER, UML)

3. Identify views of data

4. Develop conceptual data model

5. Cross-check with planning

6. Specify constraints

11

Page 12: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

TOP DOWN VS BOTTOM-UP

Enterprise Analysis

Enterprise Model

Proposed Database

Target Database

Data Model*

User views

Cross-check

*Note: the terms data model, conceptual data model and ER Model are synonymous12

The enterprise model is cross-checked with the data model

Page 13: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

THE ER METHODOLOGY

13

Page 14: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ER MODEL

Introduced in 1976 Became popular Used to communicate requirements

14

A method for drawing data models

Page 15: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

Entity classes

Attributes

Multi-valued

Derived

Relationships

Degree/cardinality concepts

Class/subclass

Recursive

BASIC MODELLING CONCEPTS

15

Page 16: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ENTITY CLASSES

Entity Class – Collection of related entities.

CUSTOMER

Common nouns (concepts are fine too!)

Customers, Products, Students etc.

Cannot be attributes or proper nouns

Cannot be database concepts

CUST#

16

Page 17: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ATTRIBUTES

Attribute – Property of an Entity Class

CUSTOMER

Generally on top of eclass

or below eclass or side

Use ovals

Underline pkey

Name PhoneID

17

Page 18: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ATTRIBUTES..

CUSTOMER

Name PhoneID

WorkHome

18

Page 19: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

CUSTOMER

Name

ID

phone

MULTI-VALUED ATTRIBUTES..

An attribute which can have more than one set of valuesper entity instance.

19

Page 20: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

DERIVED ATTRIBUTES

An attribute whose value can be derived or computedfrom other attributes e.g.

Do not include derived attributes in your ER model

20

total # of students

GPA

average score

Page 21: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

RELATIONSHIPS

Relationships: logical and meaningful connectionsbetween two or more entity classes.

CUSTOMER

Name PhoneCust#

Places ORDER

Use diamonds, label

L-R, T-B ordercardinality,degree

21

Page 22: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

CARDINALITY

CARDINALITY -- Number of entities that participate in a

relationship. Can be 1:1, 1:M or M:N

Between two entity classes A and B, these are defined as follows:

1:1 -- Each instance of A is associated with one instance of B

and vice versa.

1:M -- Each instance of A is associated with many instances of B.

Each instance of B is associated with one instance of A.

M:N -- Each instance of A is associated with many instances of B

and vice versa.

22

Max cardinality rule: In > 2 way relationships,Use max cardinality

Page 23: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

DISCUSSION

IDENTIFY THE CARDINALITIES OF THE

FOLLOWING RELATIONSHIPS

company -- president

instructor -- students

flights -- pilots

city -- convention centers

department -- employees

sports team (“pro”) -- players

company -- city

books – authors

city -- subdivisions

23

Page 24: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

DEGREE OF A RELATIONSHIP

The Degree of a relationship: The number of entityclasses that participate in the relationship:

24

CUSTOMER Places ORDER

PRODUCTS

If it is one UnaryIf two BinaryIf three TernaryIf four Quarternary

Page 25: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

DEGREE..physician chair of assoc.

25

Max cardinality rule:In > 2 way relationships,Use max cardinality

Page 26: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

CUST.

OLD CUST.

CLASS/SUBCLASS RELATIONSHIPS..

Is-a

Class/Superclass

Sub-classes

Class/subclass: Entity classes can be grouped into parent/child or superclass/class or Class/subclassrelationships based on common characteristics. NEW CUST.

26

Page 27: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

CUST.

OLD CUST.

CLASS/SUBCLASS RELATIONSHIPS..

Is-a

Class/Superclass

Sub-classes

The attr. of a sub-class are inherited fromthe parent class,but can have additionalattributes

NEW CUST.

Join dt

Member#

27

Page 28: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ABBREVIATED CLASS/SUBCLASS

CAR

GM

Is-a

Class/Superclass

FORD

(Exclusive, Non exhaustive)

28

Page 29: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

SUMMARY OF CONCEPTS

Entity – Individual example of person, place or thing.Entity Class – Collection of related entities.Attributes – Properties of entity classes about which we would like to collect information.Multi-valued – An attribute with more than one set of valuesattribute per entity instance.Relationship -- Logical and meaningful connection between two or more entity classes.Class/subclass- Grouping of entities based on common char.Cardinality -- Number of entities participating in a relationship.Degree -- Number of eclasses participating in a relationship.Unary / -- A relationship among entities within an recursive eclass

29

Page 30: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

Entity classes

Relationships

Attributes

Multivalued attributes

Class/ subclass

1 : 1

1 : M

M : N

NOTATION

THE ER

30

Page 31: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

DRAWING THE ER CHART

Identify the eclasses (and attributes)

Identify relationships among eclasses

decide which relationships to show

verbalize and map relationships

Use rectangles for eclasses , diamonds

for the relationships

Depict cardinalities

Draw attributes (underline Pkey)

Handle the special cases

31

Page 32: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

AN EXAMPLE ER CHART

CUSTOMER

ORDERS

Places

Cust#Cust# NameName

PRODUCTSAre for

32

Page 33: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ER CORRECT EXAMPLES

33

Page 34: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ER INCORRECT EXAMPLES

House

1403 W Adams

34

Page 35: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

1. A product can be on one or more orders

2. A student can have one or more loans at a bank. The bank maintains the following information ss#, name, address, loan id, amt, duration, balance, branch#, branch_mgr.

3. A judge tries cases in a court. A case can be a civil case or a criminal case.

4. The DMV issues several types of licenses to drivers: passenger car, chauffeur, motorcycle, farm vehicle.

5. A basketball team plays games against other teams.

EXAMPLE PROBLEMSMODEL THE FOLLOWING USING ER

35

Page 36: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ADDITIONAL COMMENTSBuild model around central e-class

Use only vertical and horizontal lines

Decide whether attributes belong with

eclasses, or relationships

Assume additional attributes if needed

Do not show computed attributes or values

Avoid cycles

Refine, refine...

36

Page 37: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ER CHECK LIST

All entity classes depicted?

sub classes shown?

cardinalities shown?

All attributes included/labelled?

multi-valued attr. Shown (if any)?

computed attr. omitted?

pkeys marked? Fkeys omitted?

Relationships correct/labelled?

relationship attributes? recursive?

cycles avoided?

37

Once an ER diagram is drawn, go through this check list:

Page 38: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ER ADVANCED SEMANTICS

38

Page 39: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

EXCLUSIVE AND NON-EXCLUSIVE

BooksIs

a

Fictionnon-

Fiction

EXCLUSIVE

Books

Is a

Science Poetry

NON-EXCLUSIVE

39

Arts History

Page 40: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

40

EXHAUSTIVE AND NON-EXHAUSTIVE

BooksIs

a

Fictionnon-

Fiction

EXHAUSTIVE

Books

Is a

Literature Poetry

NON-EXHAUSTIVE

Page 41: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

Books

Computers Business

ER ADVANCED SEMANTICS..

NON-EXCLUSIVE AND

NON-EXHAUSTIVE

Is a

41

Page 42: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

RELATIONSHIP ATTRIBUTES

CLIENT

sells

HOUSE

AGENT

Insert sale date?commission?

42

Page 43: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

UNARY/RECURSIVE RELATIONSHIPS

EmployeeEmployee

Unary 1:1

EmployeeEmployee

Unary 1:M

relationships among entities within an eclass

ElderJacobsSmithWhite

ElderJacobsSmithWhite

43

Page 44: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

EXCLUSIVE: When an entity of an entity class belongs to one or other of the

subtypes given (i.e. the eclass cannot be classified into more than one subtype)

NON EXCLUSIVE: When an entity of an entity class belongs to more than one

subtype given (i.e. the classification is non-exclusive)

EXHAUSTIVE: When all possible subtypes have been enumerated [listed].

(i.e. there are no more subtypes)

NON EXHAUSTIVE: When there are some subtypes which have not been

enumerated (all subtypes are not listed).

ER ADVANCED SEMANTICS..

Note: A subtype is equivalent to a subclass

44

Page 45: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ER ADVANCED SEMANTICS

Mandatory 1

cardinality

Optional 0, 1

cardinality

1,2..M cardinality

Optional 0,1..M

cardinality

Note: You can ignore min/ Max Cardinalities unless you are specifically asked to represent them.

45

Page 46: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

ER ADVANCED SEMANTICS..

Person: Child

Proj mgr: Proj (assume every proj has one proj manager and every project manager has at least one proj)

Person: Spouse

Faculty: Office (assume every faculty has one office and each office is occupied by at least one faculty)

Student: Major(assume every student has one major and each major has at least one student)

46

Page 47: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

What are the sources of info. for database analysis?

What are the outputs of database analysis?

How can we distinguish between an attr. and an entity class?

When is an ER model complete?

Are foreign keys shown on ER?

What are examples of performance constraints?

What is the difference between domain and business constraints?

DISCUSSION

47

Page 48: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

Would the name of the organization be included in

an ER diagram?

Draw ER for: Customer places order with salesperson

Suppose a company has eclasses, R,S & T. If R and S,

T & S and R & T are related, draw an ER diagram.

Suppose you have an organization having entity

classes P, Q and R and S. Assuming P & Q; R & Q;

P&R; R&S are related, draw an ER diagram.

DISCUSSION..

48

Page 49: DATABASE ANALYSIS Chandra S. Amaravadi 1. IN REQUIREMENTS ANALYSIS.. Overview of database analysis (requirements) User views Integrity constraints Steps

49