relationships

22
Relationships

Upload: aphrodite-charles

Post on 30-Dec-2015

19 views

Category:

Documents


1 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Relationships

Relationships

Page 2: Relationships

LO

Today you are Learning

1. Understand the need for a relational database structure

2. Be able to create ERDs of the relationship

3. Use software to model and create a relational database

10/03/2014

Page 3: Relationships

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 single entity– Person – Employee– Object - Book– Event - Project

Page 4: Relationships

R.D.B.M.S - Attributes

• Attributes describe the properties of an entity

• It’s easiest to think of attributes as fields

Page 5: Relationships

Relationships

Page 6: Relationships

ERDs

Entity relationship diagram

Page 7: Relationships

Relationships

• One to one 1:1

• One to many 1:M

• Many to Many M:M

Page 8: Relationships

Relationships

• One to one 1:1

• Teacher - classrooms

• One to many 1:M

• Teacher - courses

• Many to Many M:M

• Teachers - Students

Page 9: Relationships

Relationship?

Page 10: Relationships

Money

Page 11: Relationships

Relationships.....

Page 12: Relationships

Relationships.....

Page 13: Relationships

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

Page 14: Relationships

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 database

HINT: There are 4 entities. All relationships are one-to-many

Page 15: Relationships

Worked Example 2

Page 16: Relationships

Worked Example 3

• Did you get something like this?

Album NameArtists Track Name

Genres

Page 17: Relationships

LO

Creating a relationship

• Load up the Actors database from the Cambridge Tech website

• Create a ‘Oscars’ Table to join the data

Page 18: Relationships

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.

Page 19: Relationships
Page 20: Relationships
Page 21: Relationships

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.

Page 22: Relationships