CS4710 Introduction to Database Systems
Instructor:
Yi-Shin Chen
Office: EECS 3201
Email: yishin@cs.nthu.edu.tw
Office Hour: Tu. 1-2PM, Th. 3-4pm
Cons:
• The transaction errors cannot be detected on time
• The business did not know the current state
1950 : Univac had developed a magnetic tape
1951 : Univac I delivered to the
US Census Bureau
Con:
• Navigational programming interfaces are too-level
• Need to use very primitive and procedural database operations
Manual
Record
Managers
Punched-Card
Record Managers
Programmed Record
Managers
• Birth of high-level programming languages
• Batch processing
1900 1955
On-line Network
Databases
• Indexed sequential records
• Data independence
• Concurrent Access
1965 -1980
2007/3/01 CS4710 Introduction to Database
S stems
2
1
(Contd.)
E.F. Codd outlined the relational model
• Give Database users high-level set-oriented data access operations
Relational Databases && Client-
Server Computing
• Uniform representation
• 1985: first standardized of SQL
• Unexpected benefit
• Client-Server
•Because of SQL, ODBC
• Parallel processing
•Relational operators naturally support pipeline and partition parallelism
• Graphical User Interface
•Easy to render a relation
Multimedia Databases
• Richer data types
• OO databases
• Unifying procedures and data
• (Universal Server)
• Projects that push the limits
• NASA EOS/DIS projects • Oracle, Informix, Ingres
1970 1980 1995 2000
2007/3/01 CS4710 Introduction to Database
S stems
3
Data model: a collection of concepts for describing data
Schema: a description of a particular collection of data, using the a given data model
Relational model of data: the most widely used model
}
}
Main concept → relation , basically a table with rows and columns.
Every relation has a schema → describes the columns, or fields
2007/3/01
World
Using a model
Schema that represents the World Car
Using ER Model drives
People
CS4710 Introduction to Database
S stems
4
2
Introduced by Peter Chen; ACM TODS, March 1976
} http://bit.csc.lsu.edu/~chen/
2007/3/01 CS4710 Introduction to Database
S stems
Peter Chen. "English Sentence Structure and
Entity-Relationship Diagram." Information
Sciences, Vol. 1, No. 1, Elsevier, May 1983,
Pages 127-149
Peter Chen. "A Preliminary Framework for
Entity-Relationship Models." Entity-Relationship
Approach to Information Modeling and Analysis,
(edited by P. Chen), North-Holland (Elsevier),
1983, Pages 19 - 28
2007/3/01 CS4710 Introduction to Database
S stems
6
5
3
Based on a perception of a real world, which consists
}
A set of basic objects
⇒
Entities
}
Relationships among objects
Entity: Real-world object distinguishable from other objects
Entity Set: A collection of similar entities. E.g., all employees.
}
Presented as:
7 2007/3/01 CS4710 Introduction to Database
S stems
An entity is described (in DB) using a set of attributes
}
All entities in an entity set have the same set of attributes
}
Attribute can be considered as a function that maps an entity into a domain
E.g.: S#: entity → integer
}
Presented as:
8 2007/3/01 CS4710 Introduction to Database
S stems
4
Composite vs. Simple:
}
Useful when we sometimes need to refer to the entire attributes as a unit and sometimes to each of components
Multi-valued vs. Single Valued:
}
An attribute with a set of values for a same entity
2007/3/01 CS4710 Introduction to Database
S stems
9
Derived vs. Stored:
}
Can be derived from either other attributes or related entities
Null attribute:
}
Not applicable for an attribute; or exist but missing; or not known
10 2007/3/01 CS4710 Introduction to Database
S stems
5
Requirements of the Company (oversimplified for illustrative purposes)
}
}
}
}
The company is organized into departments. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager.
Each department controls a number of projects . Each project has a name, number and is located at a single location.
We store each employee's social security number, address, salary, sex, and birthdates. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee.
Each employee may have a number of dependents. For each dependent, we keep track of their name, sex, birthdates, and relationship to employee.
2007/3/01 CS4710 Introduction to Database
S stems
11
2007/3/01 CS4710 Introduction to Database
S stems
12
6
2007/3/01 CS4710 Introduction to Database
S stems
13
Relationship: Association among two or more entities
Relationship Set: Collection of similar relationships.
}
Relationship set are presented as:
}
The relationship cannot exist without having corresponding entities
2007/3/01
2-ary relationship set : Relates entity sets Student and Course
CS4710 Introduction to Database
S stems
14
7
Same entity set could participate in different relationship sets, or in different “roles” in same set
Student Enrolled Course
2007/3/01 CS4710 Introduction to Database
S stems
15
Role: the function that an entity plays in a relationship is called its role
Student Enrolled Course
}
Normally implicit
Recursive relationship
}
Same entity set participates more than once in a relationship in different roles
}
Role name become essential
2007/3/01 CS4710 Introduction to Database
S stems
16
8
N-ary Relationship Set R :
}
}
Relates N entity sets E
1 entities e
1
⊆
E
1
, ..., e n
... E n
⊆
E n
; each relationship in R involves
Formal definition:
{ ( e
1
, L , e
2
) e
1
∈
E
1
, L , e n
∈
E n
}
}
Example 3-ary relationship:
2007/3/01 CS4710 Introduction to Database
S stems
17
# of entities to which another entity can be associated via a relationship set
}
Depends on the real-world modeled by the relationship set
Possible mapping cardinality of (binary) relation R between two entity sets A and B
}
One-to-one (1:1): Woman marrying men
Men
}
Many-to-one (N:1): Children Having mothers
Children
Mary
Have
Women
Mothers
}
One-to-many (1:N): Mothers having children
Mothers
Have Children
}
Many-to-many (M:N) : Students enrolled in courses
Student
Enrolled Course
2007/3/01 CS4710 Introduction to Database
S stems
18
9
The (min,max) Notation Relationship Constraints
Employee
Employee
2007/3/01
Manages
Works for
CS4710 Introduction to Database
S stems
Department
Department
19
May have descriptive attributes
Student Enrolled Course
}
Must be uniquely identified by participating entities, without reference to descriptive attributes
Can students take the same course several times?
2007/3/01
Student Enrolled
CS4710 Introduction to Database
S stems
Course
20
10
S
1 z
S
2 z
S
3 z
S
4 z
S
5 z
S
6 z
Student
1
Enrolled r
1 r
2 r
3 r
4 r
5 r
6
1
Course z
C
1 z
C
2 z
C
3 z
C
4 z
C
5 z
C
6
2007/3/01 CS4710 Introduction to Database
S stems
21
S
1 z
S
2 z
S
3 z
S
4 z
S
5 z
S
6 z
S
7 z
2007/3/01
Student
N
Enrolled r
5 r
6 r
7 r
1 r
2 r
3 r
4
CS4710 Introduction to Database
S stems
1
Course z
C
1 z
C
2 z
C
3
22
11
S
1 z
S
2 z
S
3 z
S
4 z
2007/3/01
Student
N
Enrolled r
5 r
6 r
7 r
1 r
2 r
3 r
4
CS4710 Introduction to Database
S stems
M
Course z
C
1 z
C
2 z
C
3
23
Student Enrolled Course
Student will only take a specific course once
Student Enrolled Course
Student cam take the same course several times
2007/3/01 CS4710 Introduction to Database
S stems
24
12
Number of participating entity sets in a relationship
}
}
Binary relationships: involve two entities
Ternary/N-ary relationships: involves three/N entities
NTHU
Student
Enrolled Course
}
It’s always possible to replace a non-binary relationship set by a number of distinct binary relationships
Student Enrolled Course at NTHU
2007/3/01
But, depending on the actual real-world problem, one may be more appropriate than the other
CS4710 Introduction to Database
S stems
25
Parts
Departments Parts Departments
Contracts
Suppliers
Supplies
Which one is more appropriate?
Needs
Deals
Suppliers
2007/3/01 CS4710 Introduction to Database
S stems
26
13
Requirements of the Company (oversimplified for illustrative purposes)
}
}
}
}
The company is organized into departments. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager.
Each department controls a number of projects . Each project has a name, number and is located at a single location.
We store each employee's social security number, address, salary, sex, and birthdates. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee.
Each employee may have a number of dependents. For each dependent, we keep track of their name, sex, birthdates, and relationship to employee.
2007/3/01 CS4710 Introduction to Database
S stems
27
2007/3/01 CS4710 Introduction to Database
S stems
28
14
2007/3/01
People e
1 z e
2 z e
3 z e
4 z e
5 z e
6 z e
7 z
People Dependents of
CS4710 Introduction to Database
S stems z r
1 z r
2 z r
3 z r
4 z r
5 z r
6
Dependents of
29
Entities and relationships are distinguishable using various keys
Types:
}
}
}
Superkey: a combination of one or more attributes that allow us to identify uniquely and entity in an entity set
E.g.: Student-ID, Name & Student-ID
Candidate key: a minimal superkey that uniquely identifies an entity
E.g.: Student-ID, name & address, phone#
Primary key: A candidate key chosen by DBA to identify entities of an entity
E.g.: Student-ID
2007/3/01 CS4710 Introduction to Database
S stems
30
15
Weak entity set
}
An entity set that does not have enough attributes to form a primary key
Strong entity set
}
One with primary key
How to distinguish entities of a weak entity set?
}
}
Owner entity set and weak entity set must participate in a one-tomany relationship set (one owner, many weak entities)
Weak entity set must have total participation in this identifying relationship set
2007/3/01 CS4710 Introduction to Database
S stems
31
An entity that does not have a key attribute
A weak entity must participate in an identifying relationship type with an owner or identifying entity type
Entities are identified by the combination of:
}
A partial key of the weak entity type
}
The particular entity they are related to in the identifying entity type
2007/3/01 CS4710 Introduction to Database
S stems
32
16
Why the difference?
People Dependents of
Employee Dependents of Dependents
2007/3/01 CS4710 Introduction to Database
S stems
33
2007/3/01 CS4710 Introduction to Database
S stems
34
17
High-level entity: Abstracted from a group of interconnected low-level entity and relationship types
Product Shipping Customer
Manager Decide
Machine Assigned to Employee
2007/3/01 CS4710 Introduction to Database
S stems
35
Customer Product Shipping
Manager Decide Machine
Assignment
Assigned to Employee
2007/3/01 CS4710 Introduction to Database
S stems
36
18
2007/3/01
Student
Student
Semester
Enrolled
Enrolled
Semester
CS4710 Introduction to Database
S stems
Course
Course
37
Reservation System for airline companies
}
}
Each company has many aircrafts
Each has a registration number, make, model, and the maximum capacity of passengers
Each company has many flights
Each flight departs from and arrives at registered airports
}
An airport also has an airport code, description name, city and country
}
Flight may stop at some intermediate stops
}
Customers could take a transfer flight from intermediate stops
Each flight has many seats
For every flight, the system should store a list of available seats
The seat arrangements are associated with aircrafts
Each seat can only be reserved to one customer
Customers can make reservation without reserving seats
Each flight allow 20% overbooking
2007/3/01 CS4710 Introduction to Database
S stems
38
19
The reservation system should keep
}
}
}
}
A unique identifier for each customer
This identifier is assigned automatically once customers make a new reservation in the system
Customer information
Flight information
The time that reservation was made
}
A credit-card number associated with the reservation
}
A flag which indicates whether this particular reservation is paid or not
When a reservation is paid it is transformed automatically to a ticket
The reservation can be canceled before flight departure, however the ticket is still valid (to exchange some products)
Each reservation might be associated with many flights
2007/3/01 CS4710 Introduction to Database
S stems
39
Registration System for Universities
}
Each school has many departments
}
Each department will offer many courses
Some courses are specially designed for students majoring in some subjects
Some courses will be offered regularly
For some courses, there will be many classes in one semester taught by different instructors
Some courses will have prerequisite subjects
Some classes will control the number of seats
The system should avoid time conflicts when students schedule their courses
}
For University System of Taiwan (UST)
2007/3/01 CS4710 Introduction to Database
S stems
40
20