220 likes | 293 Views
Relationships. Today you are Learning. Understand the need for a relational database structure Be able to create ERDs of the relationship Use software to model and create a relational database. 10/03/2014. R.D.B.M.S - Entities.
E N D
Today you are Learning • Understand the need for a relational database structure • Be able to create ERDs of the relationship • Use software to model and create a relational database 10/03/2014
R.D.B.M.S - Entities • A relational database consists of multiple tables joined (linked) together by relationships • Each table should contain data about a singleentity • Person – Employee • Object - Book • Event - Project
R.D.B.M.S - Attributes • Attributes describe the properties of an entity • It’s easiest to think of attributes as fields
ERDs Entity relationship diagram
Relationships • One to one 1:1 • One to many 1:M • Many to Many M:M
Relationships • One to one 1:1 • Teacher - classrooms • One to many 1:M • Teacher - courses • Many to Many M:M • Teachers - Students
Draw the relationship shown below • One to one 1:1 • Teacher - classrooms • One to many 1:M • Teacher - courses • Many to Many M:M • Teachers - Students
Worked Example 1 • Look at the iTunes database on the next slide • Draw an ERD of the entities you would expect to see if this was converted into a relational databaseHINT: There are 4 entities. All relationships are one-to-many
Worked Example 3 • Did you get something like this? Artists Album Name Track Name Genres
Creating a relationship • Load up the Actors database from the Cambridge Tech website • Create a ‘Oscars’ Table to join the data
ENFORCE REFERENTIAL INTEGRITY • An enforced relationship ensures each value entered in a foreign key column matches an existing value in the related primary key column.
Cascade Update Fields • cascading updates only update existing records so that if you were to make a change to the customers table, all instances of the customer id would be changed in the customer orders table.