Professional Documents
Culture Documents
()?
... *! * ISO/IEC 12207:1995
ISO 12207
-...
-...
...
. . . . .
; .
Levels of Abstraction
Users
View 1
View 2
View 3
DB
Conceptual schema:
Students(sid: string, name: string, login: string, age: integer, gpa:real) Courses(cid: string, cname:string, credits:integer) View 1 Enrolled(sid:string, cid:string, grade:string)
View 2
View 3
Course_info(cid:string, enrollment:integer)
Relations stored as unordered files. Index on first column of Students.
Physical schema:
DB
Data Independence
Applications insulated from how data is structured and stored. Logical data independence: Protection from changes in logical structure of data.
View 1
View 2
View 3
Physical data independence: Protection from changes in physical structure of data. Q: Why are these particularly important for DBMS?
DB
15
Requirements analysis
Conceptual design
Logical design
Translate E/R model into (typically) relational schema Check schema for redundancies and anomalies Consider typical workloads, and further optimise
Schema refinement
Physical design/tuning
16
Todays lecture
E/R modelling
17
Conceptual Design
What are the entities and relationships in the enterprise? What information about these entities and relationships should we store in the database? What are the integrity constraints (business rules) that hold? We can represent this information pictorially in E/R diagrams (and then map these to a relational schema later).
18
E/R basics
An entity is a real-world object that is distinguishable from other objects Each entity has attributes (with domains) A particular entity will have a value for each of its attributes An entity type defines a set of entities that have the same attributes An entity set is the collection of all entities of a particular entity type (at a particular point in time)
19
Attributes are drawn as ovals, and attached to the entity sets with lines, e.g.
NI Name dob
Employees
20
ER Diagrams - Symbols
Summary of Symbols
Key attributes
A key attribute of an entity type is an attribute whose values are distinct for each entity Sometimes several attributes (a composite attribute) together form a key
Employees
23
Relationships
A relationship type among two or more entity types defines a set of associations between entities from those types
The set of instances of the relationship type is called the relationship set
24
Relationships in E/R
Relationship types are represented by diamonds They connect the participating entity types with straight lines, e.g.
NI
Name
dob
DID
dname
budget
Employees
Works_in
Departments
25
r1
d1
r2
r3 r4
d2
d3 d4
e3 e4
e5
d5
26
Relationship attributes
NB: A relationship must be uniquely determined by the entities, without reference to the relationship attributes
NI
Name
dob
since
DID
dname
budget
Employees
Works_in
Departments
27
N-ary relationships
NI
dob
since
DID
dname
budget
Employees
Works_in2
Department
address
Locations
capacity
28
Recursive relationships
Each entity type in a relationship plays a particular role, which is associated with a role name (this is usually suppressed) An recursive relationship is when an entity type plays more than one role in the relationship type In this case the role name is required
29
30
For example:
An employee can work in many departments; a department can have many employees In contrast, each department has at most one manager
Thus we need to be able to specify the number of relationship instances that an entity can participate in. For binary relationships the possible ratios are: 1:1, 1:N, N:1, M:N
31
Cardinality ratios
1:1 1:N
M:N
32
N:1
1:1
Many-many
Many-one
One-one
Representation of Many-One
Participation constraints
Every department must have a manager This is an example of a participation constraint The participation of an entity set, E, in a relationship set R is said to be total if every entity in E participates in at least one relationship in R. (If not its participation is said to be partial)
35
Total participation is displayed as a bold line between the entity type and the relationship
NI
Name
dob
since
DID
dname
budget
Employees
Manages
Department
36
37
Dependents
38
39
ISA hierarchies
We can devise hierarchies for our entity types Name NI dob If we declare A ISA B, every Employees A entity is considered to be a B entity
rate
hours ISA cid
Temp_Emp
Contract_Emp
40
Attribute inheritance
As wed expect, attributes of superclasses are inherited by the subclasses. Thus: Temp_Emp also has attributes NI, Name and dob
41
Aggregation
Suppose we have an entity set of Projects and that each project is sponsored by one or more departments; thus
start PID budget
since
DID
dname budget
Projects
Sponsors
Departments
42
Aggregation cont.
Suppose that employees are assigned to monitor a sponsorship Monitors should be a relationship between Employees and the Sponsors relationship Aggregation allows us to indicate that a relationship set participates in another relationship set Use dashed box
43
Aggregation cont.
NI name
Employees
Monitors
until
PID
start
dname
budget
Projects
Departments
44
45