1.1 - relational database concepts.pdf

55
1 © 2011 IBM Corporation Relational Database Concepts IBM Information Management Cloud Computing Center of Competence IBM Canada Labs

Upload: thedragon-ofdestruction

Post on 13-Aug-2015

74 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1.1 - Relational database concepts.pdf

1 © 2011 IBM Corporation

Relational Database Concepts

IBM Information Management Cloud Computing Center of CompetenceIBM Canada Labs

Page 2: 1.1 - Relational database concepts.pdf

2 © 2011 IBM Corporation

• Overview

• Information and Data Models

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 3: 1.1 - Relational database concepts.pdf

3 © 2011 IBM Corporation

• Reading materials• Database Fundamentals eBook

• Chapter 1: Databases and information models• Chapter 2: The relational data model• Chapter 3: The conceptual data model (optional)• Chapter 4: Relational database design (optional)

• Videos• db2university.com course AA001EN

• Lesson 1: Relational database concepts

Supporting reading material & videos

Page 4: 1.1 - Relational database concepts.pdf

4 © 2011 IBM Corporation

• Overview

• Information and Data Models

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 5: 1.1 - Relational database concepts.pdf

5 © 2011 IBM Corporation

Data vs. Information

• Data: Collection of letters, numbers or facts

• Information: Processed data that provides value

Page 6: 1.1 - Relational database concepts.pdf

6 © 2011 IBM Corporation

Databases and DBMS• Databases

• A repository of data

• DBMS (Database management system)• Software system that manages databases

• The terms “Database”, “DBMS”, “data server”, “database server” often used interchangeably to refer to a DBMS

• Why a DBMS?• Security

• Can handle many users with good performance

• Allows for concurrency while keeping data consistent

• Protects from disaster

Page 7: 1.1 - Relational database concepts.pdf

7 © 2011 IBM Corporation

• Overview

• Information and Data Models

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 8: 1.1 - Relational database concepts.pdf

8 © 2011 IBM Corporation

Information and Data Models

Relationship between an Information Model and a Data Model

Page 9: 1.1 - Relational database concepts.pdf

9 © 2011 IBM Corporation

Data Models

• Network

• Hierarchical

• Relational

• Entity-Relationship

• Extended relational

• Semantic

• Object-oriented

• Object-relational

• Semi-structured

Page 10: 1.1 - Relational database concepts.pdf

10 © 2011 IBM Corporation

• Overview

• Information and Data Models

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 11: 1.1 - Relational database concepts.pdf

11 © 2011 IBM Corporation

Relational Model

Page 12: 1.1 - Relational database concepts.pdf

12 © 2011 IBM Corporation

Entity-Relationship Diagrams

• Building Blocks

• Entities

• Attributes

Entity

Attribute

Page 13: 1.1 - Relational database concepts.pdf

13 © 2011 IBM Corporation

Entity and Attributes

Page 14: 1.1 - Relational database concepts.pdf

14 © 2011 IBM Corporation

ER diagram

Book

Title

ISBN

Editon

Year

PricePages

Aisle

Description

Page 15: 1.1 - Relational database concepts.pdf

15 © 2011 IBM Corporation

Exercise: Identify entities and attributes

House

Date

ComputerSocial Security Number

Height Order #

Product

Phone #

Page 16: 1.1 - Relational database concepts.pdf

16 © 2011 IBM Corporation

Did you get them right?

House

Date

ComputerSocial Security Number

Height Order #

Product

Phone #

Page 17: 1.1 - Relational database concepts.pdf

17 © 2011 IBM Corporation

• Overview

• Entity-relationship diagrams

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 18: 1.1 - Relational database concepts.pdf

18 © 2011 IBM Corporation

Relationships

• Building Blocks

– Entity sets

– Relationship sets

– Crows Foot notations

Page 19: 1.1 - Relational database concepts.pdf

19 © 2011 IBM Corporation

ERD of Book

Book

Title

ISBN

Editon

Year

PricePages

Aisle

Description

Page 20: 1.1 - Relational database concepts.pdf

20 © 2011 IBM Corporation

ERD of Author

Author

Author_Id

City

Lastname

Firstname

Email

Country

Page 21: 1.1 - Relational database concepts.pdf

21 © 2011 IBM Corporation

Example 1

Page 22: 1.1 - Relational database concepts.pdf

22 © 2011 IBM Corporation

Example 2

Page 23: 1.1 - Relational database concepts.pdf

23 © 2011 IBM Corporation

One-to-one Relationship

Book AuthorAuthored By

Types of Relationships

Page 24: 1.1 - Relational database concepts.pdf

24 © 2011 IBM Corporation

One-to-many Relationships

Book AuthorAuthored By

Types of Relationships (Continued)

Page 25: 1.1 - Relational database concepts.pdf

25 © 2011 IBM Corporation

Many-to-many Relationships

Book AuthorAuthored By

Types of Relationships (Continued)

Page 26: 1.1 - Relational database concepts.pdf

26 © 2011 IBM Corporation

• Overview

• Entity-relationship diagrams

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 27: 1.1 - Relational database concepts.pdf

27 © 2011 IBM Corporation

ERD revisited

Book

Title

ISBN

Editon

Year

PricePages

Aisle

Description

Page 28: 1.1 - Relational database concepts.pdf

28 © 2011 IBM Corporation

Mapping entity to a table

Entity

Table

Book

Title

ISBN

Editon

Year

PricePages

Aisle

Description

Attributes

Columns

Page 29: 1.1 - Relational database concepts.pdf

29 © 2011 IBM Corporation

Mapping entity to a table (Continued)

Title Edition Year Price ISBN Pages Aisle Description

Database Fundamentals

1 2010 24.99 978-0-9866283-1-1

300 DB-A02

Teaches you the fundamentals of databases

Getting started with DB2 Express-C

1 2010 24.99 978-0-9866283-5-1

280 DB-A01

Teaches you the essentials of DB2 using DB2 Express-C, the free version of DB2

Table: Book

Page 30: 1.1 - Relational database concepts.pdf

30 © 2011 IBM Corporation

Mapping entity to a table (Continued)

Author_ID Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania

RO

Table: Author

Page 31: 1.1 - Relational database concepts.pdf

31 © 2011 IBM Corporation

• Overview

• Entity-relationship diagrams

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 32: 1.1 - Relational database concepts.pdf

32 © 2011 IBM Corporation

Relational Model Concepts

• Building Blocks

• Relation

• Sets

Dr. E.F. Codd of IBM in 1970: “A Relational Model for Large Shared Data Banks”

Page 33: 1.1 - Relational database concepts.pdf

33 © 2011 IBM Corporation

A Relational Database

•Relational Database

• Relation

• Relation Schema

• Relation Instance

Page 34: 1.1 - Relational database concepts.pdf

34 © 2011 IBM Corporation

A Relation

Author_ID

Lastname Firstname

Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

TUPLES

ATTRIBUTES

DEGREE=6CARDINALITY=5

AUTHOR(Author_ID: char, lastname: varchar, firstname: varchar, email: varchar, city: varchar, country: char)

Relation Schema

Relation Instance

A DOMAIN is the set of all possible values for a specific attribute

Page 35: 1.1 - Relational database concepts.pdf

35 © 2011 IBM Corporation

• Overview

• Entity-relationship diagrams

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 36: 1.1 - Relational database concepts.pdf

36 © 2011 IBM Corporation

Relational Model Constraints

Business Rules

Book AuthorAuthored By

Referencing

Data Integrity

Page 37: 1.1 - Relational database concepts.pdf

37 © 2011 IBM Corporation

ERD representation of a Relational Data Model

Primary Key

Foreign Key

Parent TableDependant Table

Page 38: 1.1 - Relational database concepts.pdf

38 © 2011 IBM Corporation

Constraints

• Entity Integrity Constraint

• Referential Integrity Constraint

• Semantic Integrity Constraint

• Domain Constraint

• Null Constraint

• Check Constraint

Page 39: 1.1 - Relational database concepts.pdf

39 © 2011 IBM Corporation

Entity Integrity Constraint

Author_ID[PK]

Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

AUTHOR

Page 40: 1.1 - Relational database concepts.pdf

40 © 2011 IBM Corporation

Entity Integrity Constraint

Author_ID[PK]

Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

AUTHOR

Page 41: 1.1 - Relational database concepts.pdf

41 © 2011 IBM Corporation

Entity Integrity Constraint

Author_ID[PK]

Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

AUTHOR

NULL

Page 42: 1.1 - Relational database concepts.pdf

42 © 2011 IBM Corporation

Entity Integrity Constraint

Author_ID[PK]

Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

AUTHOR

NULL

NULL

Page 43: 1.1 - Relational database concepts.pdf

43 © 2011 IBM Corporation

Referential Integrity Constraint

Book AuthorAuthored By

Referencing

Page 44: 1.1 - Relational database concepts.pdf

44 © 2011 IBM Corporation

Semantic Integrity Constraint

Author_ID[PK]

Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

AUTHOR

Page 45: 1.1 - Relational database concepts.pdf

45 © 2011 IBM Corporation

Semantic Integrity Constraint

Author_ID[PK]

Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

12(*)&^23

AUTHOR

Page 46: 1.1 - Relational database concepts.pdf

46 © 2011 IBM Corporation

Domain Constraint

Author_ID Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

AUTHOR

Page 47: 1.1 - Relational database concepts.pdf

47 © 2011 IBM Corporation

Domain Constraint

Author_ID Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

34

34

34

AUTHOR

Page 48: 1.1 - Relational database concepts.pdf

48 © 2011 IBM Corporation

NULL Constraint

Author_ID Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

AUTHOR

Page 49: 1.1 - Relational database concepts.pdf

49 © 2011 IBM Corporation

NULL Constraint

Author_ID Lastname Firstname Email City Country

A1 Chong Raul [email protected] Toronto CA

A2 Ahuja Rav [email protected] Toronto CA

A3 Hakes Ian [email protected] Toronto CA

A4 Sharma Neeraj [email protected] Chennai IN

A5 Perniu Liviu [email protected] Transilvania RO

NULL

NULL

AUTHOR

Page 50: 1.1 - Relational database concepts.pdf

50 © 2011 IBM Corporation

Check Constraint

Title Edition Year Price ISBN Pages Aisle Description

Database Fundamentals

1 2010 24.99 978-0-9866283-1-1

300 DB-A02

Teaches you the fundamentals of databases

Getting started with DB2 Express-C

1 2010 24.99 978-0-9866283-5-1

280 DB-A01

Teaches you the essentials of DB2 using DB2 Express-C, the free version of DB2

BOOK

Page 51: 1.1 - Relational database concepts.pdf

51 © 2011 IBM Corporation

Check Constraint

Title Edition Year Price ISBN Pages Aisle Description

Database Fundamentals

1 2010 24.99 978-0-9866283-1-1

300 DB-A02

Teaches you the fundamentals of databases

Getting started with DB2 Express-C

1 2010 24.99 978-0-9866283-5-1

280 DB-A01

Teaches you the essentials of DB2 using DB2 Express-C, the free version of DB2

2015

BOOK

Page 52: 1.1 - Relational database concepts.pdf

52 © 2011 IBM Corporation

• Overview

• Entity-relationship diagrams

• The relational model• Entity-Relationship diagrams• Types of relationships• Mapping entities to tables• Relational model concepts• Relational model constraints• Normalization

Agenda

Page 53: 1.1 - Relational database concepts.pdf

53 © 2011 IBM Corporation

Normalization■ Process in database design to remove redundancies■ Example:

Consider the following table listing all the tasks of an employee:

Problem: If John moves to a new city, all entries related to John must be updated

Page 54: 1.1 - Relational database concepts.pdf

54 © 2011 IBM Corporation

Normalization (continued)No redundancy, no anomalies, no loss of information

Page 55: 1.1 - Relational database concepts.pdf

55 © 2011 IBM Corporation

Thank you!