In the name of Allah Islamic University of Gaza Faculty of Engineering Computer Engineering Department ECOM 4113 DataBase Lab Lab # 7 ER Using ERWin El-masry 2013
Objective To be familiar with Entity Relationship Model Design using ERWin program. Introduction To ERWin ERWin is a powerful tool which allows database designers to enter their Entity Relationship (ER) diagrams in a graphical form and produce physical database designs. Model Types in ERWin: 1. Logical: A conceptual model that includes entities, relationships, and attributes. This model type is essentially at the ER modeling level. 2. Physical: A database specific model that contains relational tables, columns and associated data types. 3. Logical/Physical: A single model that includes both the conceptual level objects as well as physical level tables. In this lab we will use Logical/Physical model type. Creating ER Diagrm Using ERWin 1- Launch ERWin program. 2- File menu >> New. 2
3- Choose the type of model. Typically the Logical/Physical model type should be chosen if the final goal is to produce a relational design for the database. The target database may also be chosen. 4- Rename the model to DataBase Name. Right Click on Model Name >> properties >> Enter the new Name, e.g. COMPANY >> OK. 3
Note: 5- Adding Entity Types of the DataBase We add all Entity Types of the DataBase (strong and weak), such that ERWin will classify an entity type as weak as soon as it participates in an identifying relationship. EMPLOYEE Right Click on Entities >> New. Or Click on then click on Display Window. Name The Entity Type. DEPARTMENT 4
After adding all Entity Types of COMPANY. Note: 6- Adding Attributes of the Entity Types Multi-valued attributes cannot be modeled easily with ERWin. To handle such attributes, a separate entity type is created and a many-to-many relationship between the original entity type and new entity type will be established. EMPLOYEE RIGHT Click on Entity >> Attributs 5
Click New. Enter Attribute Name and choose its Domain (Data Type) >> OK. Datatype Tab >> choose precise Data Type. 6
If the attribute is a primary key (PK) or a part of PK, select Primary Key option in General Tab of the attribute. To add a new attribute click New and repeat previous steps. After adding All EMPLOYEE Attributes After Finish, Click OK. 7
In the same way, add Attributes of the remaining Entity Types. Note: We added a new Entity Type DLOCATION to location multi-valued attribute of DEPARTMENT Entity Type. 7- Adding Relationships between Entity Types Right Click Relationships >> New. Choose Relationship Type, Parent and Child >> OK. Relationships Types In ERWin : Identifying. Non-Identifying. Many-To-Many. Parent: is the Entity Type which we add its PK to another Entity Type in the Relationship. Child: is the Entity Type which contains the foreign key (FK). 8
Note: ERWin classifies the child entity type in an identifying relationship as weak. The new relationship is added and is reflected by a line connecting the two entity types, double click on it to edit its cardinality and other properties. Cardinality: Add the cardinality of the relationship in (min,max) natation. If the relationship has attributes, add these attributes where ERWin add the FK. COMPANY Relationships Belongs_To EMPLOYEE (1,1) Belongs (1,N) _To DEPARTMEN T Non_Identifying Relationship. We will add to each EMPLOYEE, his DEPARTMENT, then the parent is DEPARTMENT and the child is EMPLOYEE. 9
Cardinality Parent To Child DEPARTMENT To EMPLOYEE (1,1) To (1,N) Then: We search for (one to one or more) cardinalty in ERWin. 10
Note: Non_identifying relationship represented by dashed line (------), ended by solid dot where FK is added. Manages Mgr_Start_Date EMPLOYEE (0,1) Manages (1,1) DEPARTMEN T Non_Identifying Relationship. We will add to each DEPARTMENT, his MANAGER, then the parent is EMPLOYEE and the child is DEPARTMENT. Cardinality Parent To Child EMPLOYEE To DEPARTMENT (1,1) To (0,1) Then: We search for (one to zero or one) cardinalty in ERWin. 11
Add Mgr_Start_Date Attribute To DEPARTMENT 12
Supervision EMPLOYEE Supervisor (0,N) Supervised (0,1) Supervision Non_Identifying Relationship. We will add to each EMPLOYEE, his Supervisor, then the parent is EMPLOYEE as Supervisor and the child is EMPLOYEE as Supervised. Cardinality Parent To Child Supervisor To Supervisd (0,1) To (0,N) Then: We search for (zero or one to zero or more) cardinalty in ERWin. 13
Because it is a reflexive relationship, We have to rename FK. Controls DEPARTMENT (0,N) Controls (1,1) s PROJECT Non_Identifying Relationship. We will add to each PROJECT, its DEPARTMENT, then the parent is DEPARTMENT and the child is PROJECT. 14
Cardinality Parent To Child DEPARTMENT To PROJECT (1,1) To (0,N) Then: We search for (one to zero or more) cardinalty in ERWin. 15
Dependent_of DEPENDENT (1,1) Depend (0,N) ent_of EMPLOYEE Identifying Relationship. Owner Entity Type is a Parent, and the weak Entity Type is the child, then the parent is EMPLOYEE and the child is DEPENDENT. Cardinality Parent To Child EMPLOYEE To DEPENDENT (1,1) To (0,N) Then: We search for (one to zero or more) cardinalty in ERWin. 16
Notes: Identifying relationship represented by solid line () ended by solid dot towards Weak Entity Type. Weak entity types are denoted by rounded rectangles. 17
Works_ON Hours EMPLOYEE (1,N) Works_ ON (1,N) Project Many To Many Relationship. Its Parent and Child can be exchanged. Cardinality It is M-N, so we don t need to determine its cardinality again. Notes: Many to Many relationship represented by solid line,() ended by two solid dots. We will postpone addition of Hours Attribute, until we Transform Logical ER to physical ER. 18
Dept_Location DEPARTMENT (1,N) Dept_L ocation (1,N) DLOCATION Many To Many Relationship. 19
Final Logical ER Model Physical ER Model To convert Logical ER Model to Physical ER Model, we need to transform many to many relationships to their physical model. Many to Many Realtionship Transformation Select M-N relationship >> Edit menu >> Many To Many Transform. If the relationship has attributes, add them to the new Entity Type. 20
Works_ON Transform 21
Add Hours Attribute. 22
Dept_Location Transformation 23
Final Physical ER Diagram 24
EXERCISE Your task is to design a database for a clinic system, which maintains information about patients and their visits to the clinic to be treated by the physicians. Draw an ER diagram to model the application with the following assumptions. Specify key attributes of each entity type and (min, max) constraints on each relationship type. Note any unspecified requirements, and make appropriate assumptions to make the specification complete. Then Build the design using ERWin. Each patient uniquely defined by patient number, first name, last name, street, city and the patient health plan. The patient can attend many visits. Each physician has a unique physician number, first name, last name, specialty, phone, hospital. A physician is required for a visit. New physicians don't have associated visits. Each visit has visit number, visit date, VisitPayMethod (cash,check,or credit card), visit charge. A physician can treat many visits. The clinic issues a visit details to record the details about a visit. At the time goes on, there will be multiple details of the same visit. A visit detail includes a detail number, a detail charge,an optional nurse number and an associated item. All the details of the same visit have different detail number, but two different visits could have details with the same detail number. Each item includes a unique item number, an item description, an item price, and an item type. An item can be related to multiple visit details. New items may not be related to any visit details. Each nurse has a unique nurse number, first name, last name, title, specialty, phone and NursePayGrade. A nurse can provide multiple visit details or may not provide any visit details. 25