* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Chapter 3: ER Model
Survey
Document related concepts
Transcript
Data Modeling Yong Choi School of Business CSUB Part # 2 Database Collection of data in electronic format – A digital library of organization Managed by one set of software that provides access to all the data No data redundancy, data inconsistency, poor security, application-data dependency... 2 Database Management System (DBMS) Part # 2 Database software Act as an interface between application and physical data files Support centralization of data Independent of specific computer programs small (MS Access), large/popular (Oracle) 3 Part # 2 Database Models Hierarchical (Tree) Models Network Model Relational Models 4 Part # 2 Relational Database Model In the relational data model the database is represented as a group of related tables. The relational data model was introduced in 1970 by E. F. Codd of IBM published a paper in CACM entitled "A Relational Model of Data for Large Shared Data Banks". It is currently the most popular model. The mathematical simplicity and ease of visualization of the relational data model have contributed to its success. 5 Part # 2 Relational Database A schematic diagram of a relational database (a) and a sample part of a relational database showing different tables (b) 6 Part # 2 Relational database and keys A relational database is a collection of tables that are related to one another based on a common field. A field, or a collection of fields, is designated as the primary key. The primary key uniquely identifies a record in the table. When the primary key of one table is represented in a second table to form a relationship, it is called a foreign key. 7 Part # 2 Primary Key Unique identifier – Prevent confusion Cost of PK – – Last name vs. SS# SS# vs. finger print Entity Integrity Rule Any primary key is allowed to accept null values. 8 Part # 2 Foreign Key An attribute in one table whose values must either match the primary key in another table or be null. The database must not contain any unmatched foreign key values. 9 Primary Key Foreign Keys Part # 2 Student ID Last Name First Name Dor m 2144 Arnold Betty 3122 Taylor John Smit h Jone s 3843 Simmons Lisa Primary Key 9844 Macy Bill Key Foreign from 2837 Leath Duplicated Heather Dorm Residence primary key of Director Major entity 2293 Wrench (notTim unique) Smith Andrea Fernandez Jones Daniel Abidjan Smit h Smit h Jone s 10 Part # 2 Foreign Keys 11 Relating tables using a common field Part # 2 The primary key in the Employer table (EmployerID) is the common field that relates this table to the Position table. PositionID is the primary key in the Position table. The EmployerID field is a foreign key in this table. Primary keys can only have one occurrence in a table. Foreign keys may have multiple occurrences. 12 Why Conceptual Data Modeling is Important? Part # 2 Effective Communication Tool User involvement Independence from a particular DBMS Documentation 13 Part # 2 Entity Relationship diagram (ERD) ERD is commonly used to: Translate different views of data among managers, users, and programmers to fit into a common framework. Define data processing and constraint requirements to help us meet the different views. Help implement the database. Developed by Peter Chen (1976). 14 ERD using Chen’ Notation Part # 2 Part # 2 ER model using IE Notation 16 Part # 2 Basic Entity Relationship Diagram (ERD) Elements Entity : a collection of people, places, objects, events, concepts of interest (a table) Entity instance – a member of the Entity : a person, a place, an object … (a row in a table) Attribute - property or characteristic of interest of an entity (a field in a table) Relationship – association between entities (corresponds to primary key-foreign key equivalencies in related tables) 17 Part # 2 Entity What should be an Entity: An object that will have many instances in the database An object that will be composed of multiple attributes An object that we are trying to model What should NOT be an Entity: A user of the database system An output of the database system (e.g. a report) 18 Part # 2 Entity … Inappropriate entities System user System output Appropriate entities 19 Part # 2 Entity Instance Entity instance: a single occurrence of an entity. entity instance Student Last ID Name First Name 2144 Arnold Betty 3122 Taylor John 3843 Simmons Lisa 9844 Macy Bill 2837 Leath Heather 2293 Wrench Tim 20 Part # 2 Attributes “describe the entity’s characteristics” Attributes are represented by an Ellipse/Oval connected to the entity with a line by Chen’s notation. Each oval contains the name of the attribute it represents. Entity: Attributes: Employee Employee-Name, Extension, Date-Of-Hire, Job-Skill-Code 21 ERD using Chen’ Notation Part # 2 Part # 2 Classes of attributes Simple Attribute Composite Attribute Derived Attributes Single-valued Multi-valued Attribute 23 Part # 2 How to find entities and attributes?? Entity: a collection of people, places, objects, events, concepts of interest look for nouns Usually, a proper noun is not a good candidate…. Attribute: property or characteristic of interest of an entity look for attribute descriptive words 24 Part # 2 (unique) Identifier “attributes that uniquely identify entity instances” Uniquely identify every instance of the entity Composite identifiers are identifiers that consist of two or more attributes Entity: Employee Identifier: Social-Security-Number 25 Part # 2 Entities??? ANG Laboratory has several chemists who work on one or more projects. Chemists also may use certain kinds of equipment on each project. The organization would like to store the chemist’s employee identification number, his/her name, up to three phone numbers, his/her project identification number and the date on which the project started. Every piece of equipment, the chemist uses, has a serial number and a cost. Also the organization would like to store the date the chemist was assigned to the project and the date an equipment item was assigned to a particular chemist working on a particular project. A chemist must be assigned at least to one project and one equipment item. Any given equipment item need not be assigned, and a given project need not be assigned either a chemist or an equipment item. 26 Part # 2 Entities Project Chemist Equipment 27 Part # 2 Attributes??? ANG Laboratory has several chemists who work on one or more projects. Chemists also may use certain kinds of equipment on each project. The organization would like to store the chemist’s employee identification number, his/her name, up to three phone numbers, his/her project identification number and the date on which the project started. Every piece of equipment, the chemist uses, has a serial number and a cost. Also the organization would like to store the date the chemist was assigned to the project and the date an equipment item was assigned to a particular chemist working on a particular project. A chemist must be assigned at least to one project and one equipment item. Any given equipment item need not be assigned, and a given project need not be assigned either a chemist or an equipment item. 28 Part # 2 Entities & Attributes Emp# Phone# Chemist Equipment Proj# Start-Date Project Serial# cost How many attributes do you (as a entity of our school database) have? – name your attributes 29 Part # 2 Example 1: find entities A department hires many employee. A employee is employed by one department. A manager manages one department. A department is managed by one manager. A person must have only one DNA pattern and that pattern must be applied to only one person. 30 Part # 2 Example 2: find entities There are several departments in School of Business and Public Administration at CSUB. Each department belongs to one school. A department has many professors, but a professor may belong to more than one department. Similarly, courses may be offered by several departments and a department must have at least one course. A professor may teach more than one student, and a student may have more than one professor. 31 Part # 2 Example 4: Find all entities, attributes, and (unique) identifier The FANTASTIC video rental company has several branches throughout the USA. The data held on each branch is the branch address made up of street, city, state, and zip code, and the telephone number. Each branch is given a branch number, which is unique throughout the company. Each branch is allocated staff, which includes a Manager. The Manager is responsible for the day-today running of a given branch. The data held on a member of staff is his or her name, position, and salary. Each member of staff is given a staff number, which is unique throughout the company. Each branch has a stock of videos. The data held on a video is the catalog number, video number, title, category, daily rental, cost, status, and the names of the main actors, and the director. The catalog number uniquely identifies each video. 32 Part # 2 Example 4: Find all entities, attributes, and (unique) identifier (con’t) A customer must first register as a member of a local branch before renting a video tape from any branches. The data held on a member is the first and last name, address, and the date that the member registered at a branch. Each member is given a member number, which is unique throughout all branches of the company. Once registered, a member is free to rent videos, up to maximum of ten at any one time. The data held on each video rented is the rental number, the full name and number of the member, the video number, title, and daily rental, and the dates the video is rented out and date returned. The rental number is unique throughout the company. 33 Part # 2 Relationships Association between entities (by lines) Any connected entities are called participants Operate in both directions Relationship between Student and Curriculum A student is enrolled in many curriculums. Each curriculum is being studied by many students. 34 Part # 2 Relationships ??? ANG Laboratory has several chemists who work on one or more projects. Chemists also may use certain kinds of equipment on each project. The organization would like to store the chemist’s employee identification number, his/her name, up to three phone numbers, his/her project identification number and the date on which the project started. Every piece of equipment, the chemist uses, has a serial number and a cost. Also the organization would like to store the date the chemist was assigned to the project and the date an equipment item was assigned to a particular chemist working on a particular project. A chemist must be assigned at least to one project and one equipment item. Any given equipment item need not be assigned, and a given project need not be assigned either a chemist or an equipment item. 35 Part # 2 Entities/Relationships & their Attributes Start-Date Proj# Project Works-On Emp# Phone# Date-Assigned Chemist Equipment Uses Serial# cost Assign-Date 36 Part # 2 Steps for creating an ERD Develop draft business rules Identify the entities (look for nouns) Identify the attributes (look for attribute descriptive words) identify draft business rules Identify the relationships (look for verb or verb phrases between entities) Identify cardinalities (look for participation related words and phrases such as zero, none, a, one, several, many…..) Using interviews and documents Optional (look for auxiliary verbs such as may, might, can and based upon own judgment..) Set business rules 37 Part # 2 Cardinality of Relationship One – to – One (1:1) One – to – Many (1:M) Each instance in the relationship will have exactly one related member on the other side A instance on one side of the relationship can have many related members on the other side, but a member on the other side will have a maximum of one related instance Many – to – Many (M:N) Instances on both sides of the relationship can have many related instances on the other side 38 Part # 2 1:1 relationship in set notation DEPARTMT EMPLOYEE 39 Part # 2 Example of 1:1 relationship A one-to-one (1:1) relationship is when at most one instance of a entity A is associated with one instance of entity B. Each employee has a one’s own office. Cardinality toward the Office entity Each office is occupied by one employee. Cardinality toward the Employee entity 40 Part # 2 1:1 relationship A person must have one and only one DNA pattern and that pattern must apply to one and only one person. 41 Part # 2 1:M relationship in set notation DEPARTMT EMPLOYEE 42 Part # 2 Example of 1:M relationship A one-to-many (1:N) relationships is when for one instance of entity A, there are zero, one, or many instances of entity B, but for one instance of entity B, there is only one instance of entity A. Each employee has many offices. Cardinality toward the Office entity Each office is occupied by one employee. Cardinality toward the Employee entity 43 Part # 2 1:M relationship Each department hires many employees, and each employee is hired by one department. HIRES DEPARTMT IS_HIRED_BY EMPLOYEE 44 Part # 2 M:N relationship in set notation WAREHOUSE PRODUCT 45 Part # 2 Example of M:N relationship A many-to-many (M:N) relationship, sometimes called non-specific, is when for one instance of entity A, there are zero, one, or many instances of entity B and for one instance of entity B there are zero, one, or many instances of entity A. A employee has multiple offices. Cardinality toward the Office entity A office must be occupied by many employee. Cardinality toward the Employee entity 46 Part # 2 M:N relationship Each student takes many classes, and each class is taken by many students. IS_TAKEN_BY STUDENT CLASS TAKE ** This is not a desirable relationship.** 47 Part # 2 Complete ER Diagram Start-Date Proj# 1 Emp# Works-On N Project Phone# Date-Assigned Chemist 1 Uses N Equipment Serial# cost Assign-Date 48 Cardinality Notations Cardinality Interpretation Minimum Instances Maximum Instances Exactly one 1 Zero or one 0 One or many 1 Many (>1) Zero or many 0 Many (>1) Part # 2 Graphic Notation 1 1 49 Part # 2 Steps for creating an ERD Develop draft business rules Identify the entities (look for nouns) Identify the attributes (look for attribute descriptive words) identify draft business rules Identify the relationships (look for verb or verb phrases between entities) Identify cardinalities (look for participation related words and phrases such as zero, none, a, one, several, many…..) Using interviews and documents Optional (look for auxiliary verbs such as may, might, can and based upon own judgment..) Set business rules 50