Relational Databases 2


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Relational Databases 2

  1. 1. Introduction to Relational Databases 2
  2. 2. Data Relationships <ul><li>A relationship is a logical link between entities based on how they interact. </li></ul><ul><li>An entity is something about which you want to store data. e.g. customers, invoices, items </li></ul>
  3. 3. Entity Relationships <ul><li>These are based on entity sets and the relationships between the sets of entities. </li></ul><ul><li>An Entity Relationship diagram is a graphical model of the database. </li></ul><ul><li>Entities whose information is dependent on each other are said to have a relationship. </li></ul><ul><li>Relationships can be one-to-one, one-to-many or many-to-many </li></ul>
  4. 4. Relationships One-To-One Each record in one table can have only one matching record in another, and each record in the other can have only one matching record in the first. Not a common relationship. One-To-Many A record in one table can have many matching records in another, but a record in the other has only one matching record in first The most common form of relationship. Many-to-Many A record in one table can have many matching records in another, and a record in the other can have many matching records in the first
  5. 5. ER Diagrams <ul><li>Entities are drawn in boxes </li></ul><ul><li>Relationships are shown as a line between boxes. </li></ul><ul><li>Arrows at the end of the lines indicate the type of relationship (1-to-1, etc) </li></ul>
  6. 6. ER Diagrams This is a one-to-many relationship - one subject can have many students This is a one-to-one relationship - one student can only have one student ID STUDENT SUBJECT STUDENT STUDENT ID
  7. 7. Creating ER Diagrams <ul><li>1. Identify the entities </li></ul><ul><li>2. Define the relationships </li></ul><ul><li>3. Define the type of relationship </li></ul><ul><li>4. Create the table structure for a database </li></ul>
  8. 8. Creating ER Diagrams Identify attributes Identify entities Year Student ID Surname Student SubjectID Name Subject
  9. 9. <ul><li>Define Relationships </li></ul><ul><ul><li>A relationship is what links entities together. </li></ul></ul>Creating ER Diagrams Student Studies Subject
  10. 10. Stage 3 <ul><li>Define type of relationship </li></ul><ul><ul><li>One to One </li></ul></ul><ul><ul><li>One to Many </li></ul></ul><ul><ul><li>Many to Many </li></ul></ul> Student Studies Subject 1 M
  11. 11. Stage 4 <ul><li>Define the table structure for the database </li></ul>Student Studies Subject 1 M 1 M 3 IT 3 12 Smith 3 1 English 2 11 Black 2 1 Maths 1 9 James 1 StudID Subject SubjectID Year Surname StudID STUDENT SUBJECT
  12. 12. Normalisation <ul><li>A technique that is used to arrange data so that data redundancy is minimised. </li></ul><ul><li>There are five ‘normal forms’ but only the first three are considered here. </li></ul>
  13. 13. Un-normalised Data Repeating groups and Null values A company manufactures and supplies a variety of products to retail suppliers .