EER Diagram
EER Diagram
MANAGEMENT
SYSTEM
Contents
Index
Control Functions
Definition of terms
Use of supertype/subtype relationships
Use of generalization and specialization techniques
Specification of completeness and disjointness constraints
Develop supertype/subtype hierarchies for realistic business
situations
EER model to Relational Model
INDEX
• Create Index
• Syntax
1> Create Index index_name on
table_name(column_name);
2> Alter table table_name add index
index_name (column_name);
• Example
1> Create Index n1 on Stud(Name);
2> Alter table Stud add Index n1 (name);
INDEX
• Show Index
• Syntax
Show Index from table_name;
• Example
Show Index from Stud;
• Drop Index
• Syntax
1> Create Index index_name on
table_name(column_name);
2> Alter table table_name add index
index_name (column_name);
• Example
1> Create Index n1 on Stud(Name);
2> Alter table Stud add Index n1 (name);
INDEX
• Create Index
• Syntax
1> DROP INDEX index_name ON
table_name;
2>Alter table table_name drop index
index_name;
• Example
1> drop Index n1 on Stud;
2> Alter table Stud drop Index n1;
INSERT AND SELECT
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
• The MySQL contains two types of Not Equal operator, which are (< >) and (! =).
The IF() function is fairly straight forward and consists of 3 elements. A condition and
values for the condition being evaluated either true or false.
Syntax:
IF(condition,true_value,false_value)
So using a simple comparison (is a number greater than 10) to return either 'yup' or
'nope'.
mysql> SELECT IF(15>10,'Yup','Nope');
+ +
| IF(15>10,'Yup','Nope') |
+ +
| Yup |
+ + 1 row
in set (0.03 sec)
select * from empl;
+--------+-------+------------+-----------+
| Emp_ID | Name | HireDate | Salary |
+--------+-------+------------+-----------+
| 1001 | John | 2002-05-15 | 140000.00 |
| 1002 | Harry | 2006-06-23 | 160000.00 |
| 1003 | Smith | 2001-07-18 | 200000.00 |
| 1004 | Jenny | 2000-08-19 | 200000.00 |
| 1005 | Hyna | 2001-09-20 | 140000.00 |
+--------+-------+------------+-----------+
5 rows in set (0.00 sec)
[ELSE else_result]
END
OR
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
[ELSE result]
END;
mysql> select * from empl;
+--------+-------+------------+-----------+ mysql> select emp_id,name,salary,
| Emp_ID | Name | HireDate | Salary | -> case
+--------+-------+------------+-----------+ -> when salary<160000 then "Salary is low"
| 1001 | John | 2002-05-15 | 140000.00 | -> when salary=160000 then "Salary is Moderate"
| 1002 | Harry | 2006-06-23 | 160000.00 | -> else "salary is awesome"
| 1003 | Smith | 2001-07-18 | 200000.00 | -> end as description
| 1004 | Jenny | 2000-08-19 | 200000.00 | -> from empl;
| 1005 | Hyna | 2001-09-20 | 140000.00 | +--------+-------+-----------+--------------------+
+--------+-------+------------+-----------+ | emp_id | name | salary | description |
5 rows in set (0.00 sec) +--------+-------+-----------+--------------------+
| 1001 | John | 140000.00 | Salary is low |
| 1002 | Harry | 160000.00 | Salary is Moderate |
| 1003 | Smith | 200000.00 | salary is awesome |
| 1004 | Jenny | 200000.00 | salary is awesome |
| 1005 | Hyna | 140000.00 | Salary is low |
+--------+-------+-----------+--------------------+
SUPERTYPES AND SUBTYPES
Subtype: A subgrouping of the entities in an entity type
that has attributes distinct from those in other
subgroupings
Supertype: A generic entity type that has a relationship
with one or more subtypes
Attribute Inheritance:
Subtype entities inherit values of all attributes of the
supertype
An instance of a subtype is also an instance of the
supertype
Figure 1: Basic notation for supertype/subtype notation
a) EER
notation
16
Figure 2: Basic notation for supertype/subtype notation (cont.)
b)
Microsoft
Visio
Notation
Different modeling tools may have different notation for the same modeling constructs
17
Figure 3: Employee supertype with three subtypes
19
RELATIONSHIPS AND SUBTYPES
Relationships at the supertype level indicate that all
subtypes will participate in the relationship.
The instances of a subtype may participate in a
relationship unique to that subtype. In this situation, the
relationship is shown at the subtype level.
Figure 4: Supertype/subtype relationships in a hospital
Both
outpatients
and resident
patients are
cared for by
a
responsible
physician
21
GENERALIZATION AND
SPECIALIZATION
Generalization: The process of defining a more
general entity type from a set of more specialized entity
types. BOTTOM-UP
Specialization: The process of defining one or more
subtypes of the supertype and forming supertype/subtype
relationships. TOP-DOWN
Figure 5: Example of generalization
a) Three entity types: CAR, TRUCK, and MOTORCYCLE
So we put
the shared
attributes
in a
supertype
24
Figure 7: Example of specialization
25
Figure 8: Example of specialization (cont.)
b) Specialization to MANUFACTURED PART and PURCHASED PART
Created 2
subtypes
26
CONSTRAINTS IN SUPERTYPE /
COMPLETENESS CONSTRAINT
28
Figure 10: Examples of completeness constraints (cont.)
b) Partial specialization rule
A vehicle
could be a
car, a
truck, or
neither
29
CONSTRAINTS IN SUPERTYPE/ DISJOINTNESS
CONSTRAINT
Disjointness Constraints: Whether an instance of a
supertype may simultaneously be a member of two (or
more) subtypes
Disjoint Rule: An instance of the supertype can be only ONE
of the subtypes
Overlap Rule: An instance of the supertype could be more
than one of the subtypes
Figure 11: Examples of disjointness constraints
a) Disjoint rule
31
EXAMPLE OF DISJOINT PARTIAL
SPECIALIZATION
Figure 12: Examples of disjointness constraints (cont.)
b) Overlap rule
33
CONSTRAINTS IN SUPERTYPE/
SUBTYPE DISCRIMINATORS
Subtype Discriminator: An attribute of the supertype whose values
determine the target subtype(s)
Disjoint – a simple attribute with alternative values to indicate the possible
subtypes
Overlapping – a composite attribute whose subparts pertain to different
subtypes. Each subpart contains a boolean value to indicate whether or not the
instance belongs to the associated subtype
Figure 13: Introducing a subtype discriminator (disjoint rule)
35
Figure 14: Subtype discriminator (overlap rule)
A composite
attribute with sub-
attributes indicating
“yes” or “no” to
determine whether it
is of each subtype
36
Figure 15: Example of supertype/subtype hierarchy
37
TRANSFORMING EER DIAGRAMS
INTO RELATIONS (CONT.)
40
Figure 19 : Example of mapping an associative entity (cont.)
b) Three resulting relations
Figure 20: Example of mapping an associative entity with
an identifier
a) SHIPMENT associative entity
Figure 21: Example of mapping an associative entity with
an identifier (cont.)
b) Three resulting relations