Upload
others
View
11
Download
0
Embed Size (px)
Citation preview
Relational Database Concepts
1 © 2011 IBMCorporation
IBM Information Management Cloud Computing Center of Competence IBM Canada Labs
• 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 IBMCorporation
Agenda
• Reading materials
• Database Fundamentals eBook
3 © 2011 IBMCorporation
•
•
•
•
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)
Supporting reading material
• 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
4 © 2011 IBMCorporation
Data vs. Information
• Data: Collection of letters, numbers or facts
• Information: Processed data that provides value
5 © 2011 IBMCorporation
Databases and DBMS
6 © 2011 IBMCorporation
• 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
• 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
7 © 2011 IBMCorporation
Information and Data Models
Relationship between an Information Model and a Data Model
8 © 2011 IBMCorporation
Data Models
9 © 2011 IBMCorporation
• Network
• Hierarchical
• Relational
• Entity-Relationship
• Extended relational
• Semantic
• Object-oriented
• Object-relational
• Semi-structured
• 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
10 © 2011 IBMCorporation
Relational Model
11 © 2011 IBMCorporation
Entity-Relationship Diagrams
• Building Blocks
• Entities
• Attributes
Entity
Attribute
12 © 2011 IBMCorporation
Entity and Attributes
13 © 2011 IBMCorporation
ER diagram
Book
Title
ISBN
Editon
Year
PricePages
14 © 2011 IBMCorporation
Aisle
Description
Exercise: Identify entities and attributes
15 © 2011 IBMCorporation
House
ComputerSocial Security Number
Height Order #
Product
Date
Phone #
Did you get them right?
House
Date
ComputerSocial Security Number
Height Order #
Product
Phone #
16 © 2011 IBMCorporation
• 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
17 © 2011 IBMCorporation
Relationships
• Building Blocks
– Entity sets
– Relationship sets
– Crows Foot notations
18 © 2011 IBMCorporation
ERD of Book
Book
Title
ISBN
Editon
Year
PricePages
19 © 2011 IBMCorporation
Aisle
Description
ERD of Author
Author
Author_Id
City
Lastname
Firstname
Country
20 © 2011 IBMCorporation
Example 1
21 © 2011 IBMCorporation
Example 2
22 © 2011 IBMCorporation
One-to-one Relationship
Book Authored By Author
Types of Relationships
23 © 2011 IBMCorporation
One-to-many Relationships
Book AuthorAuthored By
Types of Relationships (Continued)
24 © 2011 IBMCorporation
Many-to-many Relationships
Book AuthorAuthored By
Types of Relationships (Continued)
25 © 2011 IBMCorporation
• 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
26 © 2011 IBMCorporation
ERD revisited
Book
Title
ISBN
Editon
Year
PricePages
27 © 2011 IBMCorporation
Aisle
Description
Mapping entity to a table
Entity
Table
Book
Title
ISBN
Editon
Year
PricePages
Aisle
Description
Attributes
Columns
28 © 2011 IBMCorporation
Mapping entity to a table (Continued)
29 © 2011 IBMCorporation
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
Table: Book
Mapping entity to a table (Continued)
30 © 2011 IBMCorporation
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] Transilva nia
RO
Table: Author
• 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
31 © 2011 IBMCorporation
Relational Model Concepts
32 © 2011 IBMCorporation
• Building Blocks
• Relation
• Sets
Dr. E.F. Codd of IBM in 1970:
“A Relational Model for Large Shared Data Banks”
A Relational Database
33 © 2011 IBMCorporation
• RelationalDatabase
• Relation
• Relation Schema
• Relation Instance
A Relation
TUPLES
Author_ ID
Lastname Firstna me
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
ATTRIBUTES
DEGREE=6
CARDINALITY=5
AUTHOR(Author_ID: char, lastname: varchar, firstname: varchar,
email: varchar, city: varchar, country: char)
34 © 2011 IBMCorporation
Relation
Schema
Relation Instance
A DOMAIN is the set of all possible values for a specific attribute
• 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
35 © 2011 IBMCorporation
Relational Model Constraints
Business Rules
Book Authored By Author
Referencing
Data Integrity
36 © 2011 IBMCorporation
ERD representation of a Relational Data Model
Primary Key
Foreign Key
Parent Table
Dependant Table
37 © 2011 IBMCorporation
Constraints
38 © 2011 IBMCorporation
• Entity Integrity Constraint
• Referential Integrity Constraint
• Semantic Integrity Constraint
• Domain Constraint
• Null Constraint
• Check Constraint
Entity Integrity Constraint
39 © 2011 IBMCorporation
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
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
40 © 2011 IBMCorporation
Entity Integrity Constraint
A1
AUTHOR
Author_ID
[PK]Lastname Firstname Email City Country
NULL 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
41 © 2011 IBMCorporation
Entity Integrity Constraint
A1
A4
AUTHOR
Author_ID
[PK]Lastname Firstname Email City Country
NULL Chong Raul [email protected] Toronto CA
A2 Ahuja Rav [email protected] Toronto CA
A3 Hakes Ian [email protected] Toronto CA
NULL Sharma Neeraj [email protected] Chennai IN
A5 Perniu Liviu [email protected] Transilvania RO
42 © 2011 IBMCorporation
Referential Integrity Constraint
Book Authored By Author
Referencing
43 © 2011 IBMCorporation
Semantic Integrity Constraint
44 © 2011 IBMCorporation
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
Semantic Integrity Constraint
Toronto
Author_ID
[PK]Lastname Firstname Email City Country
A1 Chong Raul [email protected] 12(*)&^23 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
45 © 2011 IBMCorporation
AUTHOR
Domain Constraint
46 © 2011 IBMCorporation
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
Domain Constraint
CA
CA
CA
Author_ID Lastname Firstname Email City Country
A1 Chong Raul [email protected] Toronto 34
A2 Ahuja Rav [email protected] Toronto 34
A3 Hakes Ian [email protected] Toronto 34
A4 Sharma Neeraj [email protected] Chennai IN
A5 Perniu Liviu [email protected] Transilvania RO
AUTHOR
47 © 2011 IBMCorporation
NULL Constraint
48 © 2011 IBMCorporation
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
NULL Constraint
Raul
Hakes
Author_ID Lastname Firstname Email City Country
A1 Chong NULL [email protected] Toronto CA
A2 Ahuja Rav [email protected] Toronto CA
A3 NULL Ian [email protected] Toronto CA
A4 Sharma Neeraj [email protected] Chennai IN
A5 Perniu Liviu [email protected] Transilvania RO
49 © 2011 IBMCorporation
AUTHOR
Check Constraint
50 © 2011 IBMCorporation
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
BOOK
Check Constraint
2010
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 with DB2
1 2015 24.99 978-0-
98662280 DB-
A01Teaches you the essentials
Express-C 83-5-1 of DB2 using
DB2 Express-
C, the free
version of
DB2
51 © 2011 IBMCorporation
BOOK
• 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
52 © 2011 IBMCorporation
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 IBMCorporation
Normalization (continued)
No redundancy, no anomalies, no loss of information
54 © 2011 IBMCorporation
55 © 2011 IBMCorporation
Thank you!