0% found this document useful (0 votes)
22 views

EER Diagram

Uploaded by

rajputajay0821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

EER Diagram

Uploaded by

rajputajay0821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

DATABASE

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;

INSERT INTO table2 (column1, column2, column3, ...)


SELECT column1, column2, column3, ...
FROM table1
WHERE condition;
EXAMPLE
 insert into emp select * from persons;

 insert into persons(id,name,address) select


id,name,address from employee where id>=4;
NOT EQUAL
• The Not Equal operators in MySQL works the same to perform an inequality test
between two expressions.

• The MySQL contains two types of Not Equal operator, which are (< >) and (! =).

• select * from employee where id<>5;


• select * from employee where id!=5;
CONTROL FUNCTIONS

• The control functions allow us a degree of


conditionality when returning result sets.
IF()

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)

mysql> select *, if(salary>140000,'High','Low') as description from empl;


+--------+-------+------------+-----------+-------------+
| Emp_ID | Name | HireDate | Salary | description |
+--------+-------+------------+-----------+-------------+
| 1001 | John | 2002-05-15 | 140000.00 | Low |
| 1002 | Harry | 2006-06-23 | 160000.00 | High |
| 1003 | Smith | 2001-07-18 | 200000.00 | High |
| 1004 | Jenny | 2000-08-19 | 200000.00 | High |
| 1005 | Hyna | 2001-09-20 | 140000.00 | Low |
+--------+-------+------------+-----------+-------------+
5 rows in set (0.00 sec)
CASE
Slightly more advanced from IF() is the CASE function that allows for more than
one comparison to be made. It is slightly different as the actual value is
specified first, then a series of comparisons are made for a potential match,
then returns a value.

Syntax: CASE value WHEN value1 THEN result1


WHEN value2 THEN result2 …

[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

All employee subtypes will have


emp nbr, name, address, and date-
hired

Each employee subtype will also


have its own attributes

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

Only resident patients are


assigned to a bed

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

All these types of vehicles have common attributes


23
Figure 6: Example of generalization (cont.)

b) Generalization to VEHICLE supertype

So we put
the shared
attributes
in a
supertype

24
Figure 7: Example of specialization

a) Entity type PART

Only applies to manufactured


parts

Applies only to purchased parts

25
Figure 8: Example of specialization (cont.)
b) Specialization to MANUFACTURED PART and PURCHASED PART

Created 2
subtypes

26
CONSTRAINTS IN SUPERTYPE /
COMPLETENESS CONSTRAINT

 Completeness Constraints: Whether an


instance of a supertype must also be a
member of at least one subtype
 Total Specialization Rule: Yes (double line)
 Partial Specialization Rule: No (single line)
Figure 9: Examples of completeness constraints

a) Total specialization rule

A patient must be either


an outpatient or a
resident patient

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

A patient can either be


outpatient or resident, but not
both

31
EXAMPLE OF DISJOINT PARTIAL
SPECIALIZATION
Figure 12: Examples of disjointness constraints (cont.)

b) Overlap rule

A part may be both


purchased and
manufactured

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)

A simple attribute with


different possible values
indicating the subtype

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.)

Mapping Supertype/Subtype Relationships


 One relation for supertype and for each subtype
 Supertype attributes (including identifier and
subtype discriminator) go into supertype relation
 Subtype attributes go into each subtype; primary
key of supertype relation also becomes primary
key of subtype relation
 1:1 relationship established between supertype and
each subtype, with supertype as primary table
Figure 16: Supertype/subtype relationships
Figure 18: Example of mapping an associative entity
a) An associative entity

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

Primary key differs from foreign


keys
THANKS

You might also like