Top Banner
1 Relational Database Development Alison Taylder [email protected] Consultant ITC-ILO, Turin 25 th November 2004
21

1 Relational Database Development Alison Taylder [email protected]@yahoo.co.uk Consultant ITC-ILO, Turin 25 th November 2004.

Dec 30, 2015

Download

Documents

Blake Carpenter
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Relational Database Development Alison Taylder ataylder@yahoo.co.ukataylder@yahoo.co.uk Consultant ITC-ILO, Turin 25 th November 2004.

1

Relational Database Development

Alison Taylder [email protected]

Consultant ITC-ILO, Turin

25th November 2004

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

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.

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

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.

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

4

What is a Database ? (cont.)

Example: Employee Table

Emp_Id First_Name Last_Name Dept Position Salary

1 John Smith 10 Manager 20

2 Bill Gates 20 Labourer 5

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

5

What is a Relational Database ? A relational database is one in which

relationships between tables are stored in data fields.

Emp_Id First_Name Last_Name Dept_Id

1 John Smith 10

2 Bill Gates 20

Dept_Id Dept_Name

10 Accounting

20 Sales

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

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

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

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

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

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.

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

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

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

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

<Entity Name>

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

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.

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

12

Answer 1.

WARD

NURSE PATIENT

accommodateshas assigned

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

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

A B

A B

A B

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

14

Hospital ERD v 0.1

WARD

NURSE PATIENT

accommodateshasassigned

caresfor

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

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.

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

16

Entities with Attributes in DBDesigner

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

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.

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

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.

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

19

Entities with Relationships

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

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

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

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