Database 3
Database 3
Database 3
Andrej Tunevič
andrej.tunevic@vilniustech.lt
Relational Model
Concepts
• A Relation is a mathematical concept based on the ideas
of sets
• The model was first proposed by Dr. E.F. Codd of IBM
Research in 1970 in the following paper:
– "A Relational Model for Large Shared Data Banks,"
Communications of the ACM, June 1970
• The above paper caused a major revolution in the field of
database management and earned Dr. Codd the coveted
ACM Turing Award
Outline
• Relational Model Concepts
– Domains, Attributes, and Relations
– Characteristics of Relations
• Relational Model Constrains and Relational
Database Schemas
• Update Operations, Transactions, and Dealing
with Constrain Violations
Relational Model
Concepts
• The relational model represents the database as
a collection of relations
Attributes address
name category
price
Product
name category
name
price
makes Company
Product
stockprice
buys
employs
Person
• one-one:
1 a
2 b
3 c
d
• many-one
1 a
2 b
3 c
d
• many-many
1 a
2 b
3 c
d
name category
name
price
makes Company
Product
stockprice
What does
this say ?
buys employs
Person
Product
Purchase Store
Person
Arrows in Multiway
Relationships
Q: what does the arrow mean ?
Invoice
VideoStore
Rental Movie
Person
A: if I know the store, person, invoice, I know the
movie too
Arrows in Multiway
Relationships
Q: what do these arrow mean ?
Invoice
VideoStore
Rental Movie
Person
A: store, person, invoice determines movie and
store, invoice, movie determines person
Arrows in Multiway
Relationships
Q: how do I say: “invoice determines store” ?
A: no good way; best approximation:
Invoice
VideoStore
Rental Movie
Person
Product
Purchase Store
salesperson buyer
Person
Attributes on
Relationships
date
Product
Purchase Store
Person
Converting Multi-way
Relationships to Binary
date
ProductOf Product
Purchase
StoreOf Store
BuyerOf Person
From E/R Diagrams
to Relational Schema
• Entity set → relation
• Relationship → relation
Entity Set to Relation
name category
price
Product
makes Company
Product
Stock price
Makes(product-name, product-category, company-name, year)
Product-name Product-Category Company-name Starting-year
makes Company
Product
Stock price
No need for Makes. Modify Product:
Person
Purchase( , , )
ssn name
3. Design Principles
What’s wrong?
Moral: be faithful!
Design Principles:
What’s Wrong?
date
Product
Purchase Store
Dates date
Product
Purchase Store
Moral: don’t
complicate life more
than it already is.
Person
Modeling Subclasses
Software Educational
products products
Subclasses
name in E/R
category
Diagrams
price
Product
isa isa
– SoftwareProduct field1
field2
field3
– EducationalProduct
field1
field2
field4
field5
Subclasses to Relations
Product
name category
price
Product Sw.Product
isa isa
Ed.Product
Software Product Educational Product
Company
Person
ownedByPerson ownedByPerson
Modeling Union Types
with Subclasses
Solution 2: better, more laborious
Owner
isa isa
ownedBy
Person Company
FurniturePiece
Constraints in E/R
Diagrams
• Finding constraints is part of the modeling process.
• Commonly used constraints:
price
makes
v. s.
makes
Referential Integrity
Constraints
Product makes Company