entity relationship diagrams and relational dbs

40
Entity Relationship Diagrams and Relational DBs BSAD 141 Dave Novak

Upload: darci

Post on 22-Feb-2016

88 views

Category:

Documents


0 download

DESCRIPTION

Entity Relationship Diagrams and Relational DBs. BSAD 141 Dave Novak. Topics Covered. ERD (entity relationship diagram) Data Modeling Entity – vs - Entity set Attribute – vs - Relationship Types of attributes and their domain Characteristics of relationships Degree Connectivity - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Entity Relationship Diagrams and Relational DBs

Entity Relationship Diagrams and Relational DBs

BSAD 141Dave Novak

Page 2: Entity Relationship Diagrams and Relational DBs

Topics Covered ERD (entity relationship diagram) Data Modeling

Entity –vs- Entity setAttribute –vs- Relationship

Types of attributes and their domain Characteristics of relationships

DegreeConnectivity Existence

Page 3: Entity Relationship Diagrams and Relational DBs

Modeling

Why would it be necessary or useful to model the structure of a database system?

Page 4: Entity Relationship Diagrams and Relational DBs

Modeling

Data Model

Entity-Relationship Diagram (ERD)Popular model that focuses on data

Page 5: Entity Relationship Diagrams and Relational DBs

ERD

ERD: Graphical “blueprint” for the exact design and structure of a relational DBShows details of things organization collects

data about and how those things are related

Page 6: Entity Relationship Diagrams and Relational DBs

Relational Database Management System RDBMS A very popular, widely used DBMS Made possible by modern computing power –

computer must a lot of processing work User does not need to understand the

underlying structure of the database

Page 7: Entity Relationship Diagrams and Relational DBs

Relational Databases

Based on organization of data in two-dimensional tables connected via relationships

Tables are “linked” using a common data element (attribute) that appears in both tables

By linking tables via relationships users can navigate the database and extract and combine data from different tables

Page 8: Entity Relationship Diagrams and Relational DBs

Relational Databases

The Table is the fundamental component in a relational database

All data are divided into different tables This approach provides a much easier way to

manage dataData are essentially “grouped” by common

themes and then connected by relationships in a logical manner based on the ERD

Page 9: Entity Relationship Diagrams and Relational DBs

Relational Databases

A relationship is a connection between two or more simple two-dimensional tables that consist of rows (entity / records) and columns (attributes / fields) of data

Each entity is a unique observation and the attributes are the common characteristics that are used to describe all the entities

Page 10: Entity Relationship Diagrams and Relational DBs

Relational Databases

Power of an RDBs comes from ability to quickly find and bring together data stored in separate tables using queries, forms, and reports

RDBs utilize the Structured Query Language (SQL)A programming language used to manage

data in a RDB

Page 11: Entity Relationship Diagrams and Relational DBs

Relational Databases

CRN DeptCourse # Title Sec

Max Enroll

Current Enroll

Start Time

End Time Days InstructorCredits

90587 BSAD 120 Prin Mgmt & Org Behavior A 40 40 9:30 10:45 T R Jones 390589 BSAD 120 Prin Mgmt & Org Behavior B 40 41 11:00 12:15 T R Jones 390593 BSAD 120 Prin Mgmt & Org Behavior C 40 40 17:00 20:00 R Viets 390594 BSAD 120 Prin Mgmt & Org Behavior D 40 24 9:05 11:50 F Viets 390595 BSAD 120 Prin Mgmt & Org Behavior E 40 39 12:20 15:00 F Viets 390599 BSAD 121 ST: Human Resources Mgmt B 40 15 15:35 16:50 M W McIntosh 390600 BSAD 132 Legal & Political Envir of Bus A 50 53 14:00 15:15 T R Monte 390603 BSAD 132 Legal & Political Envir of Bus B 50 50 15:30 16:45 T R Monte 390604 BSAD 141 Mgmt Information Systems A 50 23 9:05 10:20 M W Kraushaar 390606 BSAD 141 Mgmt Information Systems B 50 43 10:35 11:50 M W Kraushaar 390610 BSAD 141 Mgmt Information Systems C 50 50 15:35 16:50 M W Novak 390612 BSAD 142 Structured Business Prgmming A 40 9 11:00 12:15 T R Bovee 390614 BSAD 143 Struc Anyl & Dsgn Business Sys A 40 9 17:00 18:15 M W Kraushaar 390616 BSAD 146 Loc Area Net/Wrk Grp & Sm Bus A 40 11 10:35 11:50 M W Novak 390617 BSAD 150 Marketing Management A 50 53 14:00 15:15 M W Zhang 390619 BSAD 150 Marketing Management B 50 50 12:30 13:45 T R Noordewier 390621 BSAD 150 Marketing Management C 50 49 14:00 15:15 T R Noordewier 3

CLASS SECTION Table

Page 12: Entity Relationship Diagrams and Relational DBs

ReviewEMPLOYEES IN A DEPARTMENT EMPLOYEE_ID NAME SALARY POSITION . . . A091 Jane Adams 45,368.00 Computer Associate F014 Kent Fuller 34,209.00 Executive Secretary L002 LeAnn Lynn 56,129.00 Lab Manager …

What is the entity set represented here?

What is an example of an entity within the entity set?

What are some of the attributes of the entity?

Why is the first field – Employee ID – underlined?

Page 13: Entity Relationship Diagrams and Relational DBs

Primary Keys

Each record/entity must have a attribute (field/column) or set of attributes that uniquely identifies that specific entity from all the other entities stored in the table

The unique attribute (or set of attributes) is called the primary key

Page 14: Entity Relationship Diagrams and Relational DBs

Primary Keys For our purposes:

ALL relational DB tables must have a primary key

ALL entities within the table must have a unique primary key value

The primary can be created by you• Doesn’t have to provide value-added information• Can be a combination of fields/attributes• Can be sequential numbers• Can be a combination of letters and numbers• Cannot be repeated or left blank for an entity

Page 15: Entity Relationship Diagrams and Relational DBs

Review Key Terminology

Entity Set / Table (has a name that directly relates to the primary information stored in the table)

Entity / Record (this is a row in a table) Attribute / Field (this is a column in the table

that describes a characteristic of the entity) Relationship (an association or linkage

between two (+) tables)

Page 16: Entity Relationship Diagrams and Relational DBs

Different Types of Attributes

Simple –vs- composite

Single valued –vs- multi-valued

Page 17: Entity Relationship Diagrams and Relational DBs

Attribute Domain The collection or range of all possible

allowable values an attribute may take on

EmpDOB: list of all valid employee birth NumDependents: positive integers from 0 to

15Height: positive real numbers between 36.0

and 84.0 inches.UnionMember: logical yes (true) or no (false)EmpSSN: list of valid social security numbers

Page 18: Entity Relationship Diagrams and Relational DBs

Value for Each Attribute Each data attribute takes on a specific

“value”:One particular instance of an entity’s attribute e.g. Employee attributes:

EmpSSN EmpDOB NumDependents Unionmember Height

Page 19: Entity Relationship Diagrams and Relational DBs

Relationships Entities are connected to one another via

relationshipsThe association between two or more entities

We will discuss three (3) important characteristics of relationships:1) Degree2) Connectivity 3) Existence

Page 20: Entity Relationship Diagrams and Relational DBs

Relationship Degree Loosely equal to the number of entities

involved in a particular relationship Could also view this more simplistically as

the number of tables “linked” by each relationship 1= Unary (aka recursive)

2= Binary

3= Ternary

Page 21: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity Three types of connectivity relationships are

used to describe associations between the entities in different tables

How are entities logically connected in the DB?1) One-to-Many2) Many-to-Many3) One-to-One

Page 22: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity

Employee #1

Employee #2

Employee #3

CompanyVehicle #1

CompanyVehicle #2

CompanyVehicle #3

1:1

This relationship connectivity shows that each employee can be associated with only one company vehicle and that each company vehicle can be associated with only one employee.

In this case, the RDB will be structured in a manner that matches a specific employee to a specific company car each and every day. Each car would be explicitly linked to a particular employee

1

1

Employee Vehicle

Page 23: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity

Employee #1

Employee #2

Employee #3

Employee #4

AccountingDepartment

Human ResourcesDeptM

This relationship connectivity shows that each employee can be associated with only one organizational department (employees cannot simultaneously be assigned to, or work in, two different departments). However, each department can be staffed with many / multiple employees

1

1:MEmployee Department

Page 24: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity

Customer #1

Customer #2

Customer #3

Product #1

Product #2

Product #3

Product #4

M:M

This relationship connectivity shows that customer can be associated with many different products and that each product can be associated with many differentcustomers

This relationship will be modeled in a special way!!

M

M

Customer Product

Page 25: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity One-to-Many relationship

A professor can teach many different class sections

Each class section is taught by only one professor

A customer account can contain many invoices

Each invoice is associated with only one customer account

Page 26: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity

One-to-Many exampleRelationship is labeled 1:M

Professor ClassSection

Eachteaches M

Each is taughtby

1

Read: left to right on the top of the line

Read: right to left on the bottom of the line

Page 27: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity

Many-to-Many relationshipEmployee has many job skillsEach job skill can be learned by many

employees

Student can take many class sectionEach class section can be taken by many

students

Page 28: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity

One-to-One relationshipEmployee is assigned to one Company CarEach Company Car is assigned to only one

employee

Page 29: Entity Relationship Diagrams and Relational DBs

Relationship Connectivity Why does this matter?

Logically the relationship needs to make sense

Don’t want the database functionality to allow relationships that are not feasible or practical

From a practical perspective, the foreign key always goes on the many side of the relationship – need to get this correct

Special implementation of M:M & 1:1

Page 30: Entity Relationship Diagrams and Relational DBs

Relationship Existence Denotes whether participation in a

relationship is required (or not), and the minimum and maximum number of entities that participate in a particular relationship Mandatory: The existence of one entity

depends on the existence of another entity

Optional: The existence of one entity is independent of the existence of another entity

Page 31: Entity Relationship Diagrams and Relational DBs

Mandatory Relationship Existence Example

Employee #1

Employee #2

Employee #3

Employee #4

AccountingDepartment

Human ResourcesDept

1:M

The existence of an instance of employee (an individual employee) depends on the existence of a department where the employee will be assigned

In this case, the entity set Department will need to be populated before the entity set Employee is populated

Employee Department

Page 32: Entity Relationship Diagrams and Relational DBs

Optional Relationship Existence Example

Employee #1

Employee #2

Employee #3

Employee #4

AccountingDepartment

Human ResourcesDept

1:M

The existence of an instance of employee (an individual employee) is independent of the existence of a department where the employee will be assigned

In this case, the entity instance employee #4 can be created without the need to assign that employee to a department

Employee Department

Page 33: Entity Relationship Diagrams and Relational DBs

Relationship Existence Example

CRN 5099

CRN 5060

CRN 5061

CRN 5062

BSAD 141

BSAD 173

BSAD 120

1:M

Discuss…

Course Section Course

Page 34: Entity Relationship Diagrams and Relational DBs

Investigating Relationships1:M relationship

This relationship states that each supplier can provide (or distributes) many different products (1, 2, … n), but eachindividual product is provided by (or distributed by) only one supplier

In this case, the structure would not allow a specific product to be provided by (or distributed by) to more than one supplier

Supplier ProductCan provide M

Is provided by1

Page 35: Entity Relationship Diagrams and Relational DBs

Supplier ProductCan provide M

Is provided by1

Supplier ID Company Name Contact Name Contact Title Address City Region Postal Code Country Phone

2New Orleans

Cajun Delights Shelley BurkeOrder

Administrator P.O. Box 78934New

Orleans LA 70117 USA(100) 555-

4822

3Grandma Kelly's

Homestead Regina MurphySales

Representative 707 Oxford Rd. Ann Arbor MI 48104 USA(313) 555-

5735

16Bigfoot

Breweries Cheryl SaylorRegional

Account Rep.

3400 - 8th Avenue

Suite 210 Bend OR 97101 USA(503) 555-

9931

Supplier Table

Page 36: Entity Relationship Diagrams and Relational DBs

Supplier ProductCan provide M

Is provided by1

Product Table

Product ID Product Name

Supplier ID Category

Quantity Per Unit

Unit Price

Units In Stock

Units On

OrderReorder

Level

7

Uncle Bob's Organic Dried

Pears 3 Seafood12 - 1 lb

pkgs. $30.00 15 0 10

8

Northwoods Cranberry

Sauce 3Condiment

s12 - 12 oz

jars $40.00 6 0 0

4

Chef Anton's Cajun

Seasoning 2Condiment

s48 - 6 oz

jars $22.00 53 0 0

5Chef Anton's Gumbo Mix 2

Condiments 36 boxes $21.35 0 0 0

34 Sasquatch Ale 16 Beverages24 - 12 oz

bottles $14.00 111 0 15

35 Steeleye Stout 16 Beverages24 - 12 oz

bottles $18.00 20 0 15

65

Louisiana Fiery Hot

Pepper Sauce 2Condiment

s32 - 8 oz bottles $21.05 76 0 0

66Louisiana Hot Spiced Okra 2

Condiments

24 - 8 oz jars $17.00 4 100 20

Page 37: Entity Relationship Diagrams and Relational DBs

Product Table

Product ID Product Name

Supplier ID Category

Quantity Per Unit

Unit Price

Units In Stock

Units On

OrderReorder

Level

7

Uncle Bob's Organic Dried

Pears 3 Seafood12 - 1 lb

pkgs. $30.00 15 0 10

8

Northwoods Cranberry

Sauce 3Condiment

s12 - 12 oz

jars $40.00 6 0 0

4

Chef Anton's Cajun

Seasoning 2Condiment

s48 - 6 oz

jars $22.00 53 0 0

5Chef Anton's Gumbo Mix 2

Condiments 36 boxes $21.35 0 0 0

34 Sasquatch Ale 16 Beverages24 - 12 oz

bottles $14.00 111 0 15

35 Steeleye Stout 16 Beverages24 - 12 oz

bottles $18.00 20 0 15

65

Louisiana Fiery Hot

Pepper Sauce 2Condiment

s32 - 8 oz bottles $21.05 76 0 0

66Louisiana Hot Spiced Okra 2

Condiments

24 - 8 oz jars $17.00 4 100 20

Notice that SupplierID is not an attribute of Product – it is the PK of the Suppliertable and will be the FK (to the Supplier table) in the Product table

Page 38: Entity Relationship Diagrams and Relational DBs

Product ID Product Name

Supplier ID Category

Quantity Per Unit

Unit Price

Units In Stock

Units On

OrderReorder

Level

7

Uncle Bob's Organic Dried

Pears 3 Seafood12 - 1 lb

pkgs. $30.00 15 0 10

8

Northwoods Cranberry

Sauce 3Condiment

s12 - 12 oz

jars $40.00 6 0 0

4

Chef Anton's Cajun

Seasoning 2Condiment

s48 - 6 oz

jars $22.00 53 0 0

5Chef Anton's Gumbo Mix 2

Condiments 36 boxes $21.35 0 0 0

34 Sasquatch Ale 16 Beverages24 - 12 oz

bottles $14.00 111 0 15

35 Steeleye Stout 16 Beverages24 - 12 oz

bottles $18.00 20 0 15

65

Louisiana Fiery Hot

Pepper Sauce 2Condiment

s32 - 8 oz bottles $21.05 76 0 0

66Louisiana Hot Spiced Okra 2

Condiments

24 - 8 oz jars $17.00 4 100 20

Supplier ID Company Name Contact Name Contact Title Address City Region Postal Code Country Phone

2New Orleans

Cajun Delights Shelley BurkeOrder

Administrator P.O. Box 78934New

Orleans LA 70117 USA(100) 555-

4822

3Grandma Kelly's

Homestead Regina MurphySales

Representative 707 Oxford Rd. Ann Arbor MI 48104 USA(313) 555-

5735

16Bigfoot

Breweries Cheryl SaylorRegional

Account Rep.

3400 - 8th Avenue

Suite 210 Bend OR 97101 USA(503) 555-

9931

Page 39: Entity Relationship Diagrams and Relational DBs

Investigating Relationships

The 1:M relationship exampleThe Supplier ID attribute in the Product table

is a foreign key that links the individual products in the Product table to a specific supplier in the Supplier table

Page 40: Entity Relationship Diagrams and Relational DBs

Learning Outcomes1. Describe the differences between ERDs and

DFDs

2. Describe importance of relational DBs

3. Familiar with all terminology: tables, relationships, entities, attributes, keys, etc

4. Understand how to implement a relationship

5. Discuss / define the 3 characteristics of relationships