490 likes | 703 Views
DATABASE ANALYSIS. Chandra S. Amaravadi. 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. OVERVIEW OF DATABASE ANALYSIS.
E N D
DATABASE ANALYSIS Chandra S. Amaravadi
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
OVERVIEW OF DATABASE ANALYSIS
THE DEVELOPMENT CYCLE The database development cycle consists of: • Planning • Analysis (Requirements definition) • Design (Logical & Physical) • Implementation • Maintenance
DATABASE ANALYSIS Database 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 during this stage
INFORMATION COLLECTED DURING RD Two types of information are gathered: • Information regarding data structure (from Views) • Information regarding rules/constraints e.g. weight limit
IDENTIFYING DATA STRUCTURE A view is a user’s representation of data (also the way it is presented to them): • Receipts • Forms • Reports and memos • Screen displays • Schedules etc. Information identified: • Eclasses • Attributes • Rules if any
AN EXAMPLE OF A VIEW QUOTATION Quote no: A61-45 Date: June 15,’12 Qty Description Price
IDENTIFYING CONSTRAINTS INTEGRITY CONSTRAINTS Are rules to preserve integrity of the database • Domain • Business constraints • Database constraints • Entity integrity • referential integrity
EXAMPLES OF CONSTRAINTS DOMAIN CONSTRAINTS Constraints on allowable value of an attr. e.g. E_name is alphabetic, E_address is alphanumeric BUSINESS CONSTRAINTS Rules concerning data: customers, purchases etc. e.g. credit limit > $4,000, enrollment limit for course DATABASE CONSTRAINTS: ENTITY & REFERENTIAL INTEGRITY • Primary key; Pkey <> Null • Referential integrity; values of cross-reference keys in different tables must match.
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
TOP DOWN VS BOTTOM-UP Enterprise Analysis Target Database Cross-check Enterprise Model Data Model* Proposed Database User views The enterprise model is cross-checked with the data model *Note: the terms data model, conceptual data model and ER Model are synonymous
ER MODEL A method for drawing data models • Introduced in 1976 • Became popular • Used to communicate requirements
BASIC MODELLING CONCEPTS • Entity classes • Attributes • Multi-valued • Derived • Relationships • Degree/cardinality concepts • Class/subclass • Recursive
ENTITY CLASSES Entity Class – Collection of related entities. CUSTOMER CUST# • Common nouns (concepts are fine too!) • Customers, Products, Students etc. • Cannot be attributes or proper nouns • Cannot be database concepts
ATTRIBUTES Attribute – Property of an Entity Class Name Phone ID • Generally on top of eclass • or below eclass or side • Use ovals • Underline pkey CUSTOMER
ATTRIBUTES.. Home Work Phone Name ID CUSTOMER
MULTI-VALUED ATTRIBUTES.. An attribute which can have more than one set of values per entity instance. Name phone ID CUSTOMER
DERIVED ATTRIBUTES An attribute whose value can be derived or computed from other attributes e.g. • total # of students • GPA • average score Do not include derived attributes in your ER model
RELATIONSHIPS Relationships: logical and meaningful connections between two or more entity classes. Name Phone Cust# CUSTOMER Places ORDER • Use diamonds, label • L-R, T-B order cardinality, degree
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. Max cardinality rule: In > 2 way relationships, Use max cardinality
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
DEGREE OF A RELATIONSHIP The Degree of a relationship: The number of entity classes that participate in the relationship: If it is one à Unary If two à Binary If three à Ternary If four à Quarternary Places CUSTOMER ORDER PRODUCTS
DEGREE.. physician chair of assoc. Max cardinality rule: In > 2 way relationships, Use max cardinality
CLASS/SUBCLASS RELATIONSHIPS.. Class/subclass: Entity classes can be grouped into parent/child or superclass/class or Class/subclass relationships based on common characteristics. Class/ Superclass CUST. Is-a Sub -classes OLD CUST. NEW CUST.
CLASS/SUBCLASS RELATIONSHIPS.. Join dt The attr. of a sub-class are inherited from the parent class, but can have additional attributes CUST. Class/Superclass Is-a Sub -classes OLD CUST. NEW CUST. Member#
ABBREVIATED CLASS/SUBCLASS Class/ Superclass CAR Is-a GM FORD (Exclusive, Non exhaustive)
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 values attribute 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
Entity classes Relationships Attributes Multivalued attributes Class/ subclass 1 : 1 THE ER NOTATION 1 : M M : N
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
AN EXAMPLE ER CHART Cust# Name CUSTOMER Places ORDERS Are for PRODUCTS
ER INCORRECT EXAMPLES 1403 W Adams House
EXAMPLE PROBLEMS MODEL THE FOLLOWING USING ER • A product can be on one or more orders • 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. • A judge tries cases in a court. A case can be a civil case or a criminal case. • The DMV issues several types of licenses to drivers: passenger car, chauffeur, motorcycle, farm vehicle. • A basketball team plays games against other teams.
ADDITIONAL COMMENTS • Build 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...
ER CHECK LIST Once an ER diagram is drawn, go through this 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?
EXCLUSIVE AND NON-EXCLUSIVE Books Books Is a Is a non- Fiction Poetry Science History Arts Fiction NON-EXCLUSIVE EXCLUSIVE
EXHAUSTIVE AND NON-EXHAUSTIVE Books Books Is a Is a non- Fiction Poetry Literature Fiction NON-EXHAUSTIVE EXHAUSTIVE
ER ADVANCED SEMANTICS.. Books Is a Computers Business NON-EXCLUSIVE AND NON-EXHAUSTIVE
RELATIONSHIP ATTRIBUTES CLIENT Insert sale date? commission? AGENT sells HOUSE
UNARY/RECURSIVE RELATIONSHIPS relationships among entities within an eclass Employee Employee Unary 1:M Unary 1:1 Elder Jacobs Smith White Elder Jacobs Smith White
ER ADVANCED SEMANTICS.. 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). Note: A subtype is equivalent to a subclass
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.
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)
DISCUSSION • 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.. • 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.