Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
1 © 2011 IBM Corporation
Relational Database Concepts
IBM Information Management Cloud Computing Center of CompetenceIBM Canada Labs
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
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
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
5 © 2011 IBM Corporation
Data vs. Information
• Data: Collection of letters, numbers or facts
• Information: Processed data that provides value
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
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
8 © 2011 IBM Corporation
Information and Data Models
Relationship between an Information Model and a Data Model
9 © 2011 IBM Corporation
Data Models
• Network
• Hierarchical
• Relational
• Entity-Relationship
• Extended relational
• Semantic
• Object-oriented
• Object-relational
• Semi-structured
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
11 © 2011 IBM Corporation
Relational Model
12 © 2011 IBM Corporation
Entity-Relationship Diagrams
• Building Blocks
• Entities
• Attributes
Entity
Attribute
13 © 2011 IBM Corporation
Entity and Attributes
14 © 2011 IBM Corporation
ER diagram
Book
Title
ISBN
Editon
Year
PricePages
Aisle
Description
15 © 2011 IBM Corporation
Exercise: Identify entities and attributes
House
Date
ComputerSocial Security Number
Height Order #
Product
Phone #
16 © 2011 IBM Corporation
Did you get them right?
House
Date
ComputerSocial Security Number
Height Order #
Product
Phone #
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
18 © 2011 IBM Corporation
Relationships
• Building Blocks
– Entity sets
– Relationship sets
– Crows Foot notations
19 © 2011 IBM Corporation
ERD of Book
Book
Title
ISBN
Editon
Year
PricePages
Aisle
Description
20 © 2011 IBM Corporation
ERD of Author
Author
Author_Id
City
Lastname
Firstname
Country
21 © 2011 IBM Corporation
Example 1
22 © 2011 IBM Corporation
Example 2
23 © 2011 IBM Corporation
One-to-one Relationship
Book AuthorAuthored By
Types of Relationships
24 © 2011 IBM Corporation
One-to-many Relationships
Book AuthorAuthored By
Types of Relationships (Continued)
25 © 2011 IBM Corporation
Many-to-many Relationships
Book AuthorAuthored By
Types of Relationships (Continued)
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
27 © 2011 IBM Corporation
ERD revisited
Book
Title
ISBN
Editon
Year
PricePages
Aisle
Description
28 © 2011 IBM Corporation
Mapping entity to a table
Entity
Table
Book
Title
ISBN
Editon
Year
PricePages
Aisle
Description
Attributes
Columns
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
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
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
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”
33 © 2011 IBM Corporation
A Relational Database
•Relational Database
• Relation
• Relation Schema
• Relation Instance
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
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
36 © 2011 IBM Corporation
Relational Model Constraints
Business Rules
Book AuthorAuthored By
Referencing
Data Integrity
37 © 2011 IBM Corporation
ERD representation of a Relational Data Model
Primary Key
Foreign Key
Parent TableDependant Table
38 © 2011 IBM Corporation
Constraints
• Entity Integrity Constraint
• Referential Integrity Constraint
• Semantic Integrity Constraint
• Domain Constraint
• Null Constraint
• Check Constraint
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
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
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
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
43 © 2011 IBM Corporation
Referential Integrity Constraint
Book AuthorAuthored By
Referencing
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
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
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
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
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
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
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
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
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
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
54 © 2011 IBM Corporation
Normalization (continued)No redundancy, no anomalies, no loss of information
55 © 2011 IBM Corporation
Thank you!