Review of database basics
Fields Attributes ‘ atomic’ Data types Primary key Validation rules Input masks L: letter A-Z (required) ?: letter A-Z (op...
tables queries (select some data only) macros forms (on screen) reports (on paper) what the user can see add a new student...
Primary key? Starter   £4.00 3 13 1125 £2.00 2 12 1125 £4.00 1 13 1124 £3.00 1 14 1123 £2.00 2 12 1123 £4.00 3 13 1122 £2....
Database exercise
Project number Project name Employee number Employee name Rate category Hourly rate 1. consider single table Consider the ...
Entity-relationship  diagrams
Entity-relationship  diagrams
<ul><li>By the end of these exercises you should be able to: </li></ul><ul><li>explain the terms ‘entity’, ‘attribute’ and...
form student  ONE  form(s)  contains   ONE  student(s)  MANY  MANY event world record ONE  event(s)   has   ONE  world rec...
event world record ONE  event(s)   has   ONE  world record(s) MANY  MANY (  ) (  ) event world record might as well merge ...
form student  ONE  form(s)  contains   ONE  student(s)  MANY  MANY (  ) (  ) This is what you are after It makes your data...
employee project ONE  employee(s)  can work on   ONE  project(s)  MANY  MANY (  ) (  ) Impossible to do in your database! ...
husband wife mother child ward patient employee company car person main residence publisher book author book film actor fi...
Hospital ERD exercise A hospital is organised into wards. Each ward has a ward number and a name recorded, along with the ...
Police Database exercise A system for tracking the officers on different cases is needed within a police unit. Each office...
publisher book author film actor director student course customer product stock item supplier staff employee project Other...
Project number Project name Employee number Employee name Rate category Hourly rate 1. consider single table Consider the ...
Impossible to do in your database! Needs to be ‘resolved’… a MANY-to-MANY relationship employee project 1. first ERD Consi...
Upcoming SlideShare
Loading in …5
×

databases2

586 views
528 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
586
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • databases2

    1. 1. Review of database basics
    2. 2. Fields Attributes ‘ atomic’ Data types Primary key Validation rules Input 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, >10 list check, e.g. ‘a’ OR ‘b’ OR ‘c’ (better as a dropdown list) Design a database to store personal information of 6 th Form students
    3. 3. tables queries (select some data only) macros forms (on screen) reports (on paper) what the user can see add a new student see all students see all in Year 13 list of all students list of all in Year 13 ? Design a database to store personal information of 6 th Form students
    4. 4. Primary key? Starter £4.00 3 13 1125 £2.00 2 12 1125 £4.00 1 13 1124 £3.00 1 14 1123 £2.00 2 12 1123 £4.00 3 13 1122 £2.00 2 12 1122 price quantitySold stockNum orderNum
    5. 5. Database exercise
    6. 6. Project number Project name Employee number Employee name Rate 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 name Rate category Hourly rate 5. spot another (less obvious) Employee number Employee name Rate category Hourly rate Project number Employee number 6. …and remove it Employee number Employee name Rate category Project number Employee number Project number Project name Rate category Hourly rate 3. spot repeated groups of data… Project number Project name Employee number Employee name Rate category Hourly rate 4. …and remove them Employee number Employee name Rate category Hourly rate Project number Employee number Project number Project name
    7. 7. Entity-relationship diagrams
    8. 8. Entity-relationship diagrams
    9. 9. <ul><li>By the end of these exercises you should be able to: </li></ul><ul><li>explain the terms ‘entity’, ‘attribute’ and ‘relationship’ </li></ul><ul><li>identify whether the relationship between two ‘entities’ is </li></ul><ul><ul><ul><li>one-to-one </li></ul></ul></ul><ul><ul><ul><li>one-to-many </li></ul></ul></ul><ul><ul><ul><li>many-many </li></ul></ul></ul><ul><li>draw an ‘entity-relationship diagram’ to represent the database for a given scenario </li></ul>
    10. 10. 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 ( ) ( ) ( ) ( ) ( ) ( )
    11. 11. 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
    12. 12. form student ONE form(s) contains ONE student(s) MANY MANY ( ) ( ) This is what you are after It makes your database more efficient a ONE-to-MANY relationship form student
    13. 13. 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 project employee_project Use a ‘link’ table between them  
    14. 14. 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 <ul><li>Extensions: </li></ul><ul><li>How will you resolve the many-to-many relationships? </li></ul><ul><li>Can any of these ER diagrams be merged? </li></ul><ul><li>Come up with a primary key field for each entity. </li></ul><ul><li>Come up with all other attributes (inc. FK’s) </li></ul>
    15. 15. 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. <ul><li>What are the entities? </li></ul><ul><li>Come up with ERD’s </li></ul><ul><li>in pairs </li></ul><ul><li>Combine into one ERD </li></ul><ul><li>Come up with primary </li></ul><ul><li>key attributes for </li></ul><ul><li>each entity </li></ul><ul><li>Come up with other </li></ul><ul><li>attributes </li></ul><ul><li>(including foreign keys) </li></ul>Extension: Consider students, teachers and courses in the same way
    16. 16. 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? <ul><li>What are the entities? </li></ul><ul><li>Come up with ERD’s </li></ul><ul><li>in pairs </li></ul><ul><li>Combine into one ERD </li></ul><ul><li>Come up with primary </li></ul><ul><li>key attributes for </li></ul><ul><li>each entity </li></ul><ul><li>Resolve any many-to- </li></ul><ul><li>many relationships </li></ul><ul><li>Come up with other </li></ul><ul><li>attributes </li></ul><ul><li>(including foreign keys) </li></ul>Extension: Consider a library in the same way.
    17. 17. publisher book author film actor director student course customer product stock item supplier staff employee project Others to practice with
    18. 18. Project number Project name Employee number Employee name Rate 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 name Rate category Hourly rate 5. spot another (less obvious) Employee number Employee name Rate category Hourly rate Project number Employee number 6. …and remove it Employee number Employee name Rate category Project number Employee number Project number Project name Rate category Hourly rate 3. spot repeated groups of data… Project number Project name Employee number Employee name Rate category Hourly rate 4. …and remove them Employee number Employee name Rate category Hourly rate Project number Employee number Project number Project name
    19. 19. Impossible to do in your database! Needs to be ‘resolved’… a MANY-to-MANY relationship employee project 1. first ERD Consider the Employees and Projects table again: employee project employee_project Use a ‘link’ table between them 2. second ERD employee project employee_project Employee number Employee name Rate category Hourly rate Employee number Project number Project number Project name 3. consider attributes 4. spot repeated group of data and remove employee project employee_project Employee number Employee name Rate category Employee number Project number Project number Project name rate Rate category Hourly rate

    ×