Download Lesson 1: Relational database concepts

Document related concepts
no text concepts found
Transcript
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
12
• Entities
Entity
• Attributes
Attribute
© 2011 IBM Corporation
Entity and Attributes
13
© 2011 IBM Corporation
ER diagram
Title
Description
Aisle
Editon
Book
Year
Pages
ISBN
14
Price
© 2011 IBM Corporation
Exercise: Identify entities and attributes
House
Phone #
Social Security Number
Computer
Product
Date
Height
15
Order #
© 2011 IBM Corporation
Did you get them right?
House
Phone #
Social Security Number
Computer
Product
Date
Height
16
Order #
© 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
Aisle
Editon
Book
Year
Pages
ISBN
19
Price
© 2011 IBM Corporation
ERD of Author
Lastname
Author_Id
Author
Country
City
20
Firstname
Email
© 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
Aisle
Editon
Book
Year
Pages
ISBN
27
Price
© 2011 IBM Corporation
Mapping entity to a table
Entity
Book
Description
Aisle
Pages
Table
Title
Editon
Attributes
ISBN
Year
Price
Columns
28
© 2011 IBM Corporation
Mapping entity to a table (Continued)
Table: Book
Title
Edition
Year
Price
ISBN
Database
Fundamentals
1
2010
24.99
978-0- 300
98662
83-1-1
DBA02
Teaches you
the
fundamentals
of databases
Getting started 1
with DB2
Express-C
2010
24.99
978-0- 280
98662
83-5-1
DBA01
Teaches you
the essentials
of DB2 using
DB2 ExpressC, the free
version of
DB2
29
Pages Aisle
Description
© 2011 IBM Corporation
Mapping entity to a table (Continued)
Table: Author
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 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,
email: varchar, city: varchar, country: char)
Relation Instance
DEGREE=6
CARDINALITY=5
TUPLES
Relation
Schema
ATTRIBUTES
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
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
37
Foreign Key
© 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
[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
39
© 2011 IBM Corporation
Entity Integrity Constraint
AUTHOR
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
40
© 2011 IBM Corporation
Entity Integrity Constraint
AUTHOR
Author_ID
[PK]
Lastname
Firstname
Email
City
Country
A1
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 IBM Corporation
Entity Integrity Constraint
AUTHOR
Author_ID
[PK]
Lastname
Firstname
Email
City
Country
A1
NULL
Chong
Raul
[email protected]
Toronto
CA
A2
Ahuja
Rav
[email protected]
Toronto
CA
A3
Hakes
Ian
[email protected]
Toronto
CA
A4
NULL
Sharma
Neeraj
[email protected]
Chennai
IN
A5
Perniu
Liviu
[email protected]
Transilvania
RO
42
© 2011 IBM Corporation
Referential Integrity Constraint
Book
Authored By
Author
Referencing
43
© 2011 IBM Corporation
Semantic Integrity Constraint
AUTHOR
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
44
© 2011 IBM Corporation
Semantic Integrity Constraint
AUTHOR
Author_ID
[PK]
Lastname
Firstname
Email
City
Country
A1
Chong
Raul
[email protected]
Toronto
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 IBM Corporation
Domain Constraint
AUTHOR
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
46
© 2011 IBM Corporation
Domain Constraint
AUTHOR
Author_ID
Lastname
Firstname
Email
City
Country
A1
Chong
Raul
[email protected]
Toronto
CA
34
A2
Ahuja
Rav
[email protected]
Toronto
CA
A3
Hakes
Ian
[email protected]
Toronto
CA
34
A4
Sharma
Neeraj
[email protected]
Chennai
IN
A5
Perniu
Liviu
[email protected]
Transilvania
RO
47
34
© 2011 IBM Corporation
NULL Constraint
AUTHOR
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
48
© 2011 IBM Corporation
NULL Constraint
AUTHOR
Author_ID
Lastname
Firstname
Email
City
Country
A1
Chong
Raul
NULL
[email protected]
Toronto
CA
A2
Ahuja
Rav
[email protected]
Toronto
CA
A3
Hakes
NULL
Ian
[email protected]
Toronto
CA
A4
Sharma
Neeraj
[email protected]
Chennai
IN
A5
Perniu
Liviu
[email protected]
Transilvania
RO
49
© 2011 IBM Corporation
Check Constraint
BOOK
Title
Edition
Year
Price
ISBN
Database
Fundamentals
1
2010
24.99
978-0- 300
98662
83-1-1
DBA02
Teaches you
the
fundamentals
of databases
Getting started 1
with DB2
Express-C
2010
24.99
978-0- 280
98662
83-5-1
DBA01
Teaches you
the essentials
of DB2 using
DB2 ExpressC, the free
version of
DB2
50
Pages Aisle
Description
© 2011 IBM Corporation
Check Constraint
BOOK
Title
Edition
Year
Price
ISBN
Database
Fundamentals
1
2010
24.99
978-0- 300
98662
83-1-1
DBA02
Teaches you
the
fundamentals
of databases
2010
2015 24.99
978-0- 280
98662
83-5-1
DBA01
Teaches you
the essentials
of DB2 using
DB2 ExpressC, the free
version of
DB2
Getting started 1
with DB2
Express-C
51
Pages Aisle
Description
© 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
Related documents