Entity relationship diagrams Mr Hall What is an Entity Relationship Diagram (ERD)? An entity relationship diagram (ERD) shows the relationships of entity sets stored in a database. An entity in this context is a component of data. In other words, ER diagrams illustrate the logical structure of databases
Starter what is a primary key
Before building any database you should know: The entities Relationships Attributes
What is an entity? Entities: Each database table is about an object, person or thing: E.g. Customers Videos Products Teachers
Attributes Attributes relate to the thing….. E.g. A DVD is the entity The attributes of the DVD are:…………………….. Relationships are how the data links together.
If a key is not a PK what is it ?
Three types of entity relationship in DBMS software One to one One to many Many to many
Cardinality –line design between entities!
Student ERD task 1 Using the attributes and the entities in the image below place the correct cardinality on the ERD diagrams
Answer to student task 1 One to many relationship
why does order number have a pk next to it ? What does Key mean?
Student task 2 You are charge of setting up a new database for the school system. You know that there are 5 major Entities in the model. These are: Classes Teachers Students Grades Rooms Draw the ERD for this model, detailing the Primary and Foreign keys for each table
Example of Entity Relation Diagrams
What are keys and why do you need to know them for creating an ERD Primary Keys are unique in that table, they cannot be duplicated Foreign Keys are linking the Primary key to another table Before building any database you should know: The entities Relationships Attributes
Different keys within a database design
What would be suitable primary keys for product and customer entities ?
Answer ? PK PK
Database task Activity 1: Entity relationship diagram-Produce an entity relationship diagram (ERD) for the database by normalizing the given data to third normal form. Now we know what ERD diagrams are and how relationships are created we now need to know how to normalize data to achieve this
Firstly what is normalization-1nf the idea is is put very simply, that you reduce data down to its atomic level. The technical word is atomicity .A good way of doing that would be for example making changes to a entity so that it did not contain duplicate values So I hear you ask . What is the issue with this set of data structures we are planning to start our design off with ?
Part 1 what is the problem ? Table one has an address entity that has multiple data sets in Address should be split into separate sections ,possibly in a new entity table all of its own .IT IS NOT ATOMIC It cannot have more than one value to be 1st normal form The column is the issue here as it should not be all in one Part 2-what is the problem ? Two emails have been entered for 1 requested value .This means it cant be atomic and so is not 1st normal form **data integrity issue** Part 3-What is the problem ? Primary key should be in here only once .As it is a primary key it should be a unique identifier .If it was a foreign key it would be no problem. **data integrity issue here with two email addresses**
Solution part 1 Solution part 2 We have split all aspects of address down to atomic level Solution part 2 Email _id is a primary key and holds the individual atomic data User_id is a foreign key hence it is allowed to have duplicate data User_id references the primary key in table 1
Firstly what is normalization-2nf The idea of 2nf is that you must first be in 1st normal form and then you need to remove all partial dependencies. There must be complete dependencies in each entity. Isbn can only be in book entity table as it is dependent or fully related to book_author. Isbn would not go in book_author as it is only partially dependent on book_author
Firstly what is normalization-3nf To get to 3nf you need to have completed 1nf and 2nf. 3nf is about removing what are called transitive dependencies Look at the following table What is the issue and what is the solution
3nf what is wrong with table This table is a good example of transitive dependency The star meaning depends upon the star That is bad. The star then depends upon the review_id Solution :split off the attributes into different tables to end transitive dependency All of the transitive dependencies have now been removed
Task 1:Produce an entity relationship diagram (ERD) for the database by normalizing the given data to third normal form.