Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Data Modeling 2 Yong Choi School of Business CSUB 1 Steps for creating an ERD • Identify the entities – Look for singular nouns (in real world situation, avoid noun w/o attributes) – Also avoid proper nouns • Identify the attributes – Look for entity characteristics or properties • Identify the relationships – Look for verb (between entities) Entities??? • Made up for the class…….ambiguous… •Using original Chen’s notation 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. Entities Project Chemist Equipment Entities’ 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. entities, attributes and identifiers Emp# Phone# Chemist Equipment 6 Proj# Start-Date Project Serial# cost 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. Entities/Relationships & their Attributes Start-Date Proj# Project Works-On Emp# Phone# Date-Assigned Chemist Equipment Uses Assign-Date Serial# cost More about Relationship • Description of each relationship should be bidirectional. • Operate in both directions – Relationship between Student and Curriculum • A student is enrolled in many curriculums (student to Curr.). • Each curriculum is being studied by many students (Curr to student). Degree of Relationship • Degree of a Relationship describes the number of entity participation – Unary (Recursive) Relationship: One instance related to another of the same entity type – Binary Relationship: Instances of two different entities related to each other – Ternary Relationship: Instances of three different types related to each other Relationships • Entities can be associated with one another in relationships. • Relationship degree defines the number of entity classes participating in the relationship: – Unary relationship. – binary relationship. – ternary relationship. Degree of Relationship … Unary (recursive) Relationship • It is possible for an entity to have a relationship to itself—this is called a recursive relationship. Is supervised by supervises Binary Relationship Ternary Relationship Cardinality • One – to – One (1:1) – Each instance in the relationship will have exactly one related member on the other side • One – to – Many (1:M) – 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 Optionality • The Optionality is a property of an attribute which specify if a value is mandatory or optional. • To identify optional relationship, look for auxiliary verb such as can or may Cardinality 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 (or more) project and one (or more) equipment. Projects and equipments must be managed by only one chemist. A given project need not be assigned an equipment. 18 Complete ER Diagram Start-Date Proj# 1 Emp# Works-On N Project Phone# Date-Assigned Chemist 1 Uses N Equipment Assign-Date Serial# cost Steps for developing an ERD 2 • Identify the entities • Identify the attributes • Identify the relationships – Beginner: look for relationship-type related words and phrases such as zero, none, a, one, several, many….. – Optional relationship: look for auxiliary verbs such as may, might, can and based upon own judgment..) • Finalize business rules Data Model Notation • 1-to-1 relationship • 1-to-M relationship • M-to-N relationship Data Model Notation Data Model Notation • weak entity relationship (see the next slide) • optional relationship • recursive relationship Employee Weak Entity relationship • A weak entity is an entity that cannot be uniquely identified and existed by itself alone. • Thus, a weak entity is an entity that exists only if it is related to a set of uniquely determined entities (owners of the weak entity). – More examples on the textbook • Each employee might have none or multiple dependents. However, dependents must belong to at least one employee. EMP DEP weak entity notation 1:1 relationship A person must have one and only one DNA pattern and eac pattern must be applied to one and only one person. 1:1 with optional relationship (OR) on one side A person might not or might be a programmer, but a programmer must be a person. 1:M relationship Each department hires many employees, and each employee is hired by one department. HIRES DEPARTMT IS_HIRED_BY EMPLOYEE 1:M with OR on many side A person might be a member or might not, but could be found multiple times (if the member entity represents membership in multiple clubs, for instance). A member must have only a single person. 1:M with OR on both side A person might have no phone, one phone or lots of phones, and that a phone might be un-owned or can only be owned by a person. M:N relationship Each student takes many classes, and a class must be taken by many students. IS_TAKEN_BY CLASS STUDENT TAKE ** Many-to-many relationships cannot allowed in the data model because they cannot be represented by the relational model (see the next slide for the reason) ** Example M:N Relationship Table to represent Entity 3 to 3 30 to 30 300 to 300 3000 to 3000 30,000 to 30,000 300, 000 to 300, 000 Example of M:N Many-to-many relationships is a second sign of complex data. When x relates to many y's and y relates to many x's, it is a many-to-many relationship. In our example schema, a color swatch can relate to many types of sweaters and a type of sweater can have many color swatches. Transformation of M:N 1. When transform to relational model, many redundancies can be generated. – – CLASS The relational operations become very complex and are likely to cause system efficiency errors and output errors. Break the M:N down into 1:N and N:1 relationships using bridge entity (weak entity). ENROLL STUDENT Converting M:N Relationship to Two 1:M Relationships Bridge Entity Bridge (Associative - textbook) Entity • ENROLL entity becomes a weak entity of both STUDENT entity and CLASS entity • MUST have a composite (unique) identifier STU_NUM (from STUDENT entity) and CLASS_CODE (from CLASS entity) • Another MUST know M:N example on the textbook page 63 and 64 M:N with optionality on both side • A person might or might not work for an employer, but could certainly moonlight for multiple companies. An employer might have no employees, but could have any number of them. After broken down, optional relationship notation on both side of associative entity Recursive relationship • Each student is taught by a STA (student teaching assistant). Each STA can teach several students. • A recursive relationship is an entity is associated with itself. teaches Student is taught by