You are on page 1of 55

Relational Database Concepts

IBM Information Management Cloud Computing Center of Competence


IBM Canada Labs
1 © 2011 IBM Corporation
Agenda

• 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

2 © 2011 IBM Corporation


Supporting reading material & videos
• 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

3 © 2011 IBM Corporation


Agenda

• 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

4 © 2011 IBM Corporation


Data vs. Information

• Data: Collection of letters, numbers or facts


• Information: Processed data that provides value

5 © 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
6 © 2011 IBM Corporation
Agenda

• 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

7 © 2011 IBM Corporation


Information and Data Models

Relationship between an Information Model and a Data Model

8 © 2011 IBM Corporation


Data Models

• Network • Semantic

• Hierarchical • Object-oriented

• Relational • Object-relational

• Entity-Relationship • Semi-structured

• Extended relational

9 © 2011 IBM Corporation


Agenda

• 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

10 © 2011 IBM Corporation


Relational Model

11 © 2011 IBM Corporation


Entity-Relationship Diagrams

• Building Blocks

• Entities Entity

• Attributes Attribute

12 © 2011 IBM Corporation


Entity and Attributes

13 © 2011 IBM Corporation


ER diagram

Title
Description
Editon

Aisle Book Year

Pages
ISBN Price

14 © 2011 IBM Corporation


Exercise: Identify entities and attributes

House Phone #

Social Security Number


Computer
Product
Date

Height Order #
15 © 2011 IBM Corporation
Did you get them right?

House Phone #

Social Security Number


Computer
Product
Date

Height Order #
16 © 2011 IBM Corporation
Agenda

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

17 © 2011 IBM Corporation


Relationships

• Building Blocks

– Entity sets

– Relationship sets

– Crows Foot notations

18 © 2011 IBM Corporation


ERD of Book

Title
Description
Editon

Aisle Book Year

Pages
ISBN Price

19 © 2011 IBM Corporation


ERD of Author

Author_Id Lastname

Country Author Firstname

City Email

20 © 2011 IBM Corporation


Example 1

21 © 2011 IBM Corporation


Example 2

22 © 2011 IBM Corporation


Types of Relationships

Book Authored By Author

One-to-one Relationship

23 © 2011 IBM Corporation


Types of Relationships (Continued)

Book Authored By Author

One-to-many Relationships

24 © 2011 IBM Corporation


Types of Relationships (Continued)

Book Authored By Author

Many-to-many Relationships

25 © 2011 IBM Corporation


Agenda

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

26 © 2011 IBM Corporation


ERD revisited

Title
Description
Editon

Aisle Book Year

Pages
ISBN Price

27 © 2011 IBM Corporation


Mapping entity to a table

Title
Description
Entity Editon

Book Aisle Attributes Year

Pages
ISBN Price
Table

Columns
28 © 2011 IBM Corporation
Mapping entity to a table (Continued)

Table: Book
Title Edition Year Price ISBN Pages Aisle Description

Database 1 2010 24.99 978-0- 300 DB- Teaches you


Fundamentals 98662 A02 the
83-1-1 fundamentals
of databases
Getting started 1 2010 24.99 978-0- 280 DB- Teaches you
with DB2 98662 A01 the essentials
Express-C 83-5-1 of DB2 using
DB2 Express-
C, the free
version of
DB2

29 © 2011 IBM Corporation


Mapping entity to a table (Continued)
Table: Author
Author_ID Lastname Firstname Email City Country

A1 Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilva RO


nia

30 © 2011 IBM Corporation


Agenda

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

31 © 2011 IBM Corporation


Relational Model Concepts

Dr. E.F. Codd of IBM in 1970:


“A Relational Model for Large Shared Data Banks”

• Building Blocks

• Relation

• Sets

32 © 2011 IBM Corporation


A Relational Database

• Relational Database

• Relation

• Relation Schema

• Relation Instance

33 © 2011 IBM Corporation


A Relation
AUTHOR(Author_ID: char, lastname: varchar, firstname: varchar, Relation
email: varchar, city: varchar, country: char)
Schema
Relation Instance ATTRIBUTES

DEGREE=6 Author_ Lastname Firstna Email City Country


CARDINALITY=5 ID me

A1 Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

TUPLES A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

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


34 © 2011 IBM Corporation
Agenda

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

35 © 2011 IBM Corporation


Relational Model Constraints

Business Rules

Book Authored By Author

Referencing

Data Integrity

36 © 2011 IBM Corporation


ERD representation of a Relational Data Model
Primary Key

Parent Table
Dependant Table Foreign Key

37 © 2011 IBM Corporation


Constraints

• Entity Integrity Constraint


• Referential Integrity Constraint
• Semantic Integrity Constraint
• Domain Constraint
• Null Constraint
• Check Constraint

38 © 2011 IBM Corporation


Entity Integrity Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country
[PK]

A1 Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

39 © 2011 IBM Corporation


Entity Integrity Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country
[PK]

A1 Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

40 © 2011 IBM Corporation


Entity Integrity Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country
[PK]

A1
NULL Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

41 © 2011 IBM Corporation


Entity Integrity Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country
[PK]

A1
NULL Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4
NULL Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

42 © 2011 IBM Corporation


Referential Integrity Constraint

Book Authored By Author

Referencing

43 © 2011 IBM Corporation


Semantic Integrity Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country
[PK]

A1 Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

44 © 2011 IBM Corporation


Semantic Integrity Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country
[PK]

A1 Chong Raul rfc@ibm.com Toronto CA


12(*)&^23

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

45 © 2011 IBM Corporation


Domain Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country

A1 Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

46 © 2011 IBM Corporation


Domain Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country

A1 Chong Raul rfc@ibm.com Toronto CA


34
A2 Ahuja Rav ra@ibm.com Toronto CA
34
A3 Hakes Ian ih@ibm.com Toronto CA
34
A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

47 © 2011 IBM Corporation


NULL Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country

A1 Chong Raul rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

48 © 2011 IBM Corporation


NULL Constraint

AUTHOR
Author_ID Lastname Firstname Email City Country

A1 Chong Raul
NULL rfc@ibm.com Toronto CA

A2 Ahuja Rav ra@ibm.com Toronto CA

A3 Hakes
NULL Ian ih@ibm.com Toronto CA

A4 Sharma Neeraj ns@ibm.com Chennai IN

A5 Perniu Liviu lp@univ.com Transilvania RO

49 © 2011 IBM Corporation


Check Constraint

BOOK
Title Edition Year Price ISBN Pages Aisle Description

Database 1 2010 24.99 978-0- 300 DB- Teaches you


Fundamentals 98662 A02 the
83-1-1 fundamentals
of databases
Getting started 1 2010 24.99 978-0- 280 DB- Teaches you
with DB2 98662 A01 the essentials
Express-C 83-5-1 of DB2 using
DB2 Express-
C, the free
version of
DB2

50 © 2011 IBM Corporation


Check Constraint

BOOK
Title Edition Year Price ISBN Pages Aisle Description

Database 1 2010 24.99 978-0- 300 DB- Teaches you


Fundamentals 98662 A02 the
83-1-1 fundamentals
of databases
Getting started 1 2010
2015 24.99 978-0- 280 DB- Teaches you
with DB2 98662 A01 the essentials
Express-C 83-5-1 of DB2 using
DB2 Express-
C, the free
version of
DB2

51 © 2011 IBM Corporation


Agenda

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

52 © 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
53 © 2011 IBM Corporation
Normalization (continued)
No redundancy, no anomalies, no loss of information

54 © 2011 IBM Corporation


Thank you!
55 © 2011 IBM Corporation

You might also like