Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Relational Database Development Alison Taylder Consultant ITC-ILO, Turin 25 th November 2004.

Similar presentations


Presentation on theme: "1 Relational Database Development Alison Taylder Consultant ITC-ILO, Turin 25 th November 2004."— Presentation transcript:

1 1 Relational Database Development Alison Taylder ataylder@yahoo.co.ukataylder@yahoo.co.uk Consultant ITC-ILO, Turin 25 th November 2004

2 2 What is a Database ? A database is a structured collection of data. Data refers to the characteristics of people, things, and events. In a database each data item is stored in its own field.  For example, a person's first name, date of birth, and their postal code are each stored in separate fields. The name of a field usually reflects its contents. A postal code field might be named POSTAL-CODE or PSTL_CD.

3 3 What is a Database ? (cont.) The fields relating to a particular person, thing or event are bundled together to form a record or row.  Each row is made up of a number of fields. No two fields in a row can have the same field name. Rows describing people, things or events are bundled together to form a table.

4 4 What is a Database ? (cont.) Example:  Employee Table Emp_IdFirst_NameLast_NameDeptPositionSalary 1JohnSmith10Manager20 2BillGates20Labourer5

5 5 What is a Relational Database ? A relational database is one in which relationships between tables are stored in data fields. Emp_IdFirst_NameLast_NameDept_Id 1JohnSmith10 2BillGates20 Dept_IdDept_Name 10 Accounting 20 Sales

6 6 How do we create a Relational Database ? 1. Perform Analysis of data 2. Design Database 3. Re-Analyse data 4. Redesign Database. Iterate above steps until the design is satisfactory

7 7 Analysing Data Gather the evidence  Interview people using the data  Ask them to define the data they are working with eg. What is a claim ? How do you define a rejected claim ?  Find out where the data comes from ? Eg. Paper forms, external database  Find out how the data is used. Eg. Reporting and what is the life- cycle of the data, how it is processed

8 8 Designing a Relational Database With the help of a data model the users’ data model is transformed into a database design. The standard data model used to create a Relational Database design is called the Entity-Relationship Model.

9 9 Creating an Entity-Relationship Model Determine Potential Entities  Entities are the principal data object about which information is to be collected. Some specific examples of entities are EMPLOYEES, PROJECTS, INVOICES. An entity is analogous to a table in the relational model. Determine Relationships between Entities  A Relationship represents an association between two or more entities. An example of a relationship would be: employees are assigned to projects projects have subtasks departments manage one or more projects

10 10 First Draft Entity Relationship Diagram Draw a rough ERD on paper with Entities represented thus:  Entity names should be singular nouns. Relationships are represented as a line between the concerned entities with a short phrase describing the relationship

11 11 Exercise1. Create a rough ERD For the following example create a first cut ERD on paper:  In a hospital system, each ward has many patients who are cared for by nurses assigned to the ward.

12 12 Answer 1. WARD NURSEPATIENT accommodates has assigned

13 13 Examine Relationships Determine what type of relationships we have from the 3 below options:  i) 1:1 relationship  ii) 1:N relationship  iii) N:M relationship ABAB AB

14 14 Hospital ERD v 0.1 WARD NURSEPATIENT accommodates has assigned cares for

15 15 Enter ERD into DBDesigner Open DBDesigner  Make sure that the interface is in Design Mode (check by clicking on the menu item Display)  From the left hand side tool click on the table icon it becomes “sticky”, then stick it onto the the white space. It will be called Table_01.  To modify this entity, right click on it and select the option Edit Object. Now you can change the name.  Add all the tables from the rough ERD diagram but NOT the relationships yet.  Add some attributes to each entity. Make the first field of each entity a unique identifier (UID) eg Patient_Id, this is the primary key.

16 16 Entities with Attributes in DBDesigner

17 17 Add Relationships I Add the Ward -> Patient Relationship  Click on the button 1:n Relation Tool (Non-Identifying Relation) from the Toolbar so that it becomes sticky. Then clicking on the entity representing the “1” part of the relationship first eg. Ward then on the “N” entity eg Nurse a relationship will be created.  DBDesigner creates a foreign key column identified by (FK) in the “N” entity. What is a foreign key ?  A foreign key is an attribute that completes a relationship by identifying the parent entity.  Every relationship in the model must be supported by a foreign key.

18 18 Add Relationships II Add the Nurse -> Patient Relationship  Click on the button n:m Relation from the Toolbar so that it becomes sticky. Then clicking on one entity and then the next a relationship will be created.  DBDesigner creates a new entity to represent the N:M relationship made up entirely of the the 2 primary keys of the related entities.

19 19 Entities with Relationships

20 20 Create this database in MySQL Click on menu option Database -> Connect. Connect to database Select Database Synchronisation DBDesigner will create the tables, primary keys and foreign keys in MySQL

21 21 Advanced Exercise A company has several departments. Each department has a supervisor and at least one employee. Employees must be assigned to at least one, but possibly more departments. At least one employee is assigned to a project, but an employee may be on vacation and not assigned to any projects. The important data fields are the names of the departments, projects, supervisors and employees, as well as the supervisor and employee number and a unique project number. Create an ERD using DBDesigner from the above case study


Download ppt "1 Relational Database Development Alison Taylder Consultant ITC-ILO, Turin 25 th November 2004."

Similar presentations


Ads by Google