• No results found

Database Management Systems,

N/A
N/A
Protected

Academic year: 2021

Share "Database Management Systems,"

Copied!
27
0
0

Loading.... (view fulltext now)

Full text

(1)

Database Design Example

4/20/2015 Database Management Systems, Roya Choupani

1

(2)

Topics

 Hospital Database  E-R Design

 Entities

 Relationships

Converting E-R Model to Relational Model

 Tables  Queries

(3)

Hospital Database (1)

4/20/2015 Database Management Systems, Roya Choupani

3

 The database for a hospital or a clinic.

 It contains information about people who have been admitted

at least once in the hospital. A person can be admitted several times to the same or different wards. People are identified by a Code.

 The database should describes all the hospital’s wards,

showing for each ward the name and the respective consultant.

(4)

Hospital Database (2)

 The database should contains information about all doctors in

the hospital, giving their surnames, first names, wards, and so on.

 For each patient the given treatment at any date is stored in

(5)

E-R Model

4/20/2015 Database Management Systems, Roya Choupani

5  Entities:  Patient  Doctor  Ward  Relationships:

 A doctor works in a ward

 A patient is admitted to a ward at a given date.

 A doctor gives a treatment to a patient at a given date.  A ward has a consultant who is a doctor

(6)

Patient Entity and its Attributes

 A patient is identified by a Patient Code. The attributes are:

 PatientCode  Name  Surname  Date of Birth  Place of Birth  Gender  Address  Phone

(7)

Doctor Entity and its Attributes

4/20/2015 Database Management Systems, Roya Choupani

7

 For each doctor a code is used. The attributes are:

 DoctorID  Name  Surname  Expertise  Address  Phone

(8)

Ward Entity

 Ward has the following attributes:

 WardID  Name  Building  Phone

(9)

E-R Diagram of the Hospital

4/20/2015 Database Management Systems, Roya Choupani

(10)

Relationships(1)

 Each doctor works in a ward

 A ward has many doctors

 The relationship between ward and doctor is a one to many

(11)

Relationships(2)

4/20/2015 Database Management Systems, Roya Choupani

11

 Admission:

 A patient is admitted to a ward.

 A patient may be admitted to different wards at different dates  A ward admits many patients

(12)

Relationships(3)

 Treatment

 A doctor gives a treatment to a patient

 A doctor can give treatment to many patients

 A patient gets treatment from many doctors (at different dates)  The treatment is a many to many relationship between doctor

(13)

Relationships(4)

4/20/2015 Database Management Systems, Roya Choupani

13

 Each ward has a consultant who is a doctor.

 A doctor can be a consultant in only one ward  Each ward has only one consultant

(14)

Relational Model for the Hospital

Database

The following tables are created:

1. Patient table (patientCode primary key)

2. Doctor table (doctorID primary key, wardID foreign key) 3. Ward table (wardID primary key, Consultant is foreign

(15)

Converting Relationships

4/20/2015 Database Management Systems, Roya Choupani

15

 Admission is converted to a table as

 Admission < PatientCode, WardCode, DateAdmitted,

DateDischarged >

 PatientCode and WardCode are foreign keys

Primary Key: PatientCode+WardCode+DateAdmitted

 Treatment <PatientCode, DoctorID, Date, Treatment>

 PatientCode and DoctorID are foreign keys. Treatment is a string.  Primary Key : PatientCode+DoctorID+Date

(16)

Some Queries

 The following queries are given as example:

 Create table for ward entity  Insert data into Patient table

 Select all patients admitted on May 10, 2010  Select all patients treated by doctor ‘Hasan’

(17)

Create Ward Table

4/20/2015 Database Management Systems, Roya Choupani

17

Create Table Ward (

WardID char(10) Primary Key, WardName varchar,

Building char(5), Phone char(13) )

(18)

Insert Data into Patient Table

 Insert Into Patient (PatientCode,Name,Surname, DateOfBirth,

PlaceOfBirth, Gender, Address,Phone ) values ( 100, ‘Ali’ , ‘Velioglu’, 1980, ‘Ankara’, ‘Male’, ‘100 Yil’ , ‘123456’ )

(19)

List Patients Admitted on May 10, 2010

4/20/2015 Database Management Systems, Roya Choupani

19

Select Name, Surname

FROM Patient JOIN Admission ON Patient.PatientCode = Admission.PatientCode

(20)

List Patients Treated by Doctor ‘Hasan’

SELECT Patient.Name, Patient.Surname FROM Patient, Treatment, Doctor

WHERE

Patient.PatientCode = Treatment.PateintCode AND

Treatment.DoctorID = Doctor.DoctorID AND

(21)

Company Example

4/20/2015 Database Management Systems, Roya Choupani

21

 A company has several projects.

 Each project is carried out in a different city, has a start date,

period and budget.

 For each project some products are needed.

(22)

Entities

 Project:

 Attributes: Project Code, Project Name, Project Start Date,

Project Duration, Project Budget

 Product:

 Attributes: Product Code, Product Name, Price

 Supplier:

(23)

Relationships

4/20/2015 Database Management Systems, Roya Choupani

23

 A supplier SUPPLIES some products for a project  A project may get products from different suppliers  A supplier may supply a product for different projects

 There is a ternary relationship between supplier, product, and

(24)
(25)

Create Table for Relationship

4/20/2015 Database Management Systems, Roya Choupani

25

Create table supplies (

supplyCode Integer Primary key,

sID Integer References supplier(ID),

pcode Integer References product(code), pID Integer References project(code), quantity Integer,

supplyDate Date )

(26)

Summary

 Read the problem requirements very carefully  Find entities and relationships

 Create E-R model for the database

 Convert E-R model to Relational model

 Create tables

 Insert data into the tables

 Write some queries to use the database (depends on the

(27)

Questions?

4/20/2015 Database Management Systems, Roya Choupani

References

Related documents

Additionally, the table provides various measures of goodness of fit for the model including the Likelihood Ratio (LR), the pseudo R-squared (Pseudo R 2 ), the Akaike

We analyze the galactic kinematics and orbit of the host star LHS 1815 and find that it has a large probability (P thick /P thin =6482) to be in the thick disk with a much

– Large page size – data related to x stored in same page; hence additional page transfer can be avoided. – Small page size – reduce transfer time, reduce buffer size in

3.1 Textbooks and Readings 3.2 Staff 4 Course Assessment 4.1 Exams 4.2 Homework 4.3 Software Project 4.4 Oracle 4.5 Class Participation 4.6 Late Policy 4.7 Grading.. 5 Other

Indications for newborn screening for in utero substance exposure:  The neonate is exhibiting signs or symptoms of withdrawal..  Maternal urine toxicology is positive

The KD Method models the original KD relay as well as a number of electromechanical and microprocessor relay types that utilize the same basic technology. The KD Method can be

Detail System design: Inform and involve the organization, aim of detailed design, project management of MIS detailed design, identify dominant and trade off criteria, define

Barbara for the student medical report on human resources and you feel comfortable and students have questions in urop the research.. Above information is to mit student medical