databases3b
TRANSCRIPT
Review of
database basics
A2 Applied ICT
FieldsAttributes ‘atomic’
Data typesPrimary key
Validation rulesInput masks
L: letter A-Z (required)?: letter A-Z (optional)0: number 0-9 (required)9: number (optional)
range (or limit) check, e.g. between 10 and 20, >10list check, e.g. ‘a’ OR ‘b’ OR ‘c’(better as a dropdown list)
Design a database to store personal information of 6th Form students
A2 Applied ICT
tables queries(select some data only)
macros
forms(on screen)
reports(on paper)
what the user can see
add a new student
see all studentssee all in Year
13
list of all students
list of all in Year 13
?
Design a database to store personal information of 6th Form students
A2 Applied ICT
orderNum stockNum quantitySold price
1122 12 2 £2.00
1122 13 3 £4.00
1123 12 2 £2.00
1123 14 1 £3.00
1124 13 1 £4.00
1125 12 2 £2.00
1125 13 3 £4.00
Primary key?Starter
A2 Applied ICT Database exercise
A2 Applied ICT
Project number Project name
Employee number Employee nameRate category
Hourly rate
1. consider single table
Consider the Employees and Projects table on the webpage
2. assign primary key(s)?
Project number Project name
Employee number Employee nameRate category
Hourly rate
5. spot another (less obvious)
Employee number Employee nameRate category
Hourly rate
Project numberEmployee number
6. …and remove it
Employee number Employee nameRate category
Project numberEmployee number
Project number Project name
Rate categoryHourly rate
3. spot repeated groups of data…
Project number Project name
Employee number Employee nameRate category
Hourly rate
4. …and remove them
Employee number Employee nameRate category
Hourly rate
Project numberEmployee number
Project number Project name
A2 Applied ICT
Entity-relationsh
ip diagrams
A2 Applied ICT
By the end of these exercises you should be able to:
• explain the terms ‘entity’, ‘attribute’ and ‘relationship’
• identify whether the relationship between two ‘entities’ is• one-to-one• one-to-many• many-many
• draw an ‘entity-relationship diagram’ to represent the database for a given scenario
form student
ONE form(s) contains ONE student(s) MANY MANY
event world record
ONE event(s) has ONE world record(s)MANY MANY
employee project
ONE employee(s) can work on ONE project(s) MANY MANY
( ) ( )
( ) ( )
( ) ( )
event world record
ONE event(s) has ONE world record(s)MANY MANY( ) ( )
event
world record
might as well merge into the one table(nothing to be gained from having two)
a ONE-to-ONE relationship
form student
ONE form(s) contains ONE student(s) MANY MANY( ) ( )
This is what you are afterIt makes your database more efficient
a ONE-to-MANY relationship
form student
employee project
ONE employee(s) can work on ONE project(s) MANY MANY( ) ( )
Impossible to do in your database!Needs to be resolved…
a MANY-to-MANY relationship
employee project
employee projectemployee_project
Use a ‘link’ table between them
husband wife
mother child
ward patient
employee company car
person main residence
publisher book
author book
film actor
film director
student A-level course
customer product
stock item supplier
Extensions:• How will you resolve the many-to-many relationships?
• Can any of these ER diagrams be merged?
• Come up with a primary key field for each entity.• Come up with all other attributes (inc. FK’s)
Hospital ERD exercise
A hospital is organised into wards. Each ward has a ward number and a name recorded, along with the number of beds in that ward.
Each ward is staffed by nurses. They have their staff number and name recorded and are assigned to a single ward.
Each patient in the hospital has a patient identification number and their name, address and date of birth are recorded. Each patient is under the care of a single consultant and is assigned to a single ward.
Each consultant is responsible for a number of patients. Consultants have their staff number, name and specialism recorded.
• What are the entities?
• Come up with ERD’s in pairs
• Combine into one ERD
• Come up with primary key attributes for each entity
• Come up with other attributes (including foreign keys)Extension:Consider students, teachers and courses in the same way
nursepatient wardconsultant
staffIDTitleForenameSurname
staffIDTitleForenameSurnamewardID (FK)
patientIDTitleForenameSurnameAdmissionDatestaffID (FK)wardID (FK)
wardIDwardNameBuildingFloorTel
Police Database exercise
A system for tracking the officers on different cases is needed within a police unit.
Each officer belongs to a single department. Officers are allocated to cases. Each officer can be allocated to more than one case at any given time and each case could be worked on by a number of officers.
Each case has a single supervising officer (or ‘supervisor’) in charge of it who may supervise more than one case at a time.
The following information needs to be stored:case ID number; type of case; description of the case; the date a case is opened (and closed); the result of the case; officers’ name, rank, department and gender; supervisors’ name and rank
Extension: where would the date an officer was assigned to a case go?
• What are the entities?
• Come up with ERD’s in pairs
• Combine into one ERD
• Come up with primary key attributes for each entity
• Resolve any many-to- many relationships
• Come up with other attributes (including foreign keys)Extension:Consider a library in the same way.
supervisor
Cases
Officers Department
Officers
Cases
Clue for previous situation