relationships

Post on 30-Dec-2015

19 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

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

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

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

R.D.B.M.S - Attributes

• Attributes describe the properties of an entity

• It’s easiest to think of attributes as fields

Relationships

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

Relationship?

Money

Relationships.....

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

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

Worked Example 2

Worked Example 3

• Did you get something like this?

Album NameArtists Track Name

Genres

LO

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.

top related