chapter 2 entity relationship (e-r model)

23
14/06/56 1 Data Management Chapter 2 Entity Relationship (E-R Model) Modern Management and Information Technology Collage of Arts, Media and Technology, Chiang Mai University E-R E-R E-R E-R

Upload: others

Post on 05-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

14/06/56

1

Data Management

������������

Chapter 2

Entity Relationship (E-R Model)

Modern Management and Information Technology

Collage of Arts, Media and Technology,

Chiang Mai University

������

• ������ ���� ��������

• ������ ������� � ����������������������

• ���� ������������ � E-R

• ��! ��"#$�%&���������� � E-R

• �����%'������� � E-R

• (��$�)���$ )*%�

• ��"#�������(������+��,$

• ���)*%���

• ���� ������� � E-R � -�*����������

14/06/56

2

������������� ��������

������������� *��.�'������ ���� �+�&���������� ��%&�%�� ����������������' ��%'�*���/ �%&��%&'������������ ��� -���*������%'���� ������������0������*� �������%&�%� ��� �'�1����%&�������� �%&�*�*��������

��������������������������������������

�� �%& 2.1 *��'��������� ��������������������

14/06/56

3

��������������������������������������1. ������ ������� ����� (Conceptual Model)

� -����������C(������� ���*D1 ����($� ����������

2. ������ ������E�'�� (External Model)

� -�������1���������������� �%&*���������

3. ������ ������E�'�� (Internal Model)

� -����������������������� ����)��������� E�'�������� �������0�������*� �(�

4. ������ ��������'E�+ (Physical model)

� -������E�+����� ����� ����1� ���� ����*������R���� ���1 ��#$�����R����

������������� (E-R Model) �$�%�����

• �� ����� �� ��������������������� �!�� ���"���#�$$%&����"'()�! �*

• �$$'��� !�� ���%&�()���$,��* ���$ '�-�,���������!#.���$$/���� ���*&��� 0 �!1 "������ ,"2�!��

14/06/56

4

&�'���()*�$+ � ���������� E-R

&�%�,���������������� E-R

E-R Model ��� �$$'��� !�� ��� �� ,������!�$$'��� !/���� ���"���)�$�����3) (Conceptual Level) B)* E-R Model �&� ��#��, $�����H 3 � ��)�!�&I

1. K�%30& (entity)

2. � %%�3$3�%� (attributes) � !�0 �� K�%30&

3. ��������������� �! K�%30& (relationship)

14/06/56

5

-���./$ (Entity)

R Entity ���*-S! �3�!� !��� ��0-T%&������-$ ,�����0,0 �!'�, �%30& ���1 ()�

R Entity �''�#.� $T��� , �-��%&� , �0T,��V� ��� �3�!� !%&����� , �� "2�"�,��,K$�� ���

R ��H��,WV� '�"2���#�&���&�*�X��X�� ����&2�� ,��,�$Y�*"�#.� ������

��,ZS,W� �'��*� 2�I��&*�

�����.�.%/* (Attribute)

Attribute #.��3�!%&�"2� �3$�*-S!�TV��,WV�� ! Entity ��S�! 1 2 � Entity � !��,ZS,W� '�#��, $)��* Attribute 2�� -�,T� , Z , %&� *� , $ ��B%� , �V� , ���� ,�32� , ���%&�����&*� #.�0�����23,%&� *� "� Entity ��S�! 1 '�0� !�& Attribute%&���� �,��'�"2���H��,WV� ���% �%� Attribute ��S�! Attribute ����&2�� ,��,�$Y�*"�%&�#.������� ���� %%�3$3�%�")#.�(%'$� ��,K'��&,���%�����*� %%�3$3�%���I� 1

14/06/56

6

�����.�.%/* (Attribute)

StudentStu_Id

Name

Address GenderTel

Major

��.��� Attribute

1. Simple Attribute ���*-S! � %�3$3�0�%&�(� �����-�$ !* *()� &, 2 � �*T Z �-��Y�,������

2. Composite Attribute ���*-S! � %�3$3�0�%&������-�$ !* *()� &, 2 � Attribute %&� *� �����-�$ !#.�� %�3$3�0�* *1 ()� #.� ��%&� -�� ��Y '�!���)

14/06/56

7

*��'���(�C+�)*���)�)�*$

StudentStu_Id

Name

Major GenderTel

Adress

� �B�30� %�3$3�0�

��%&�

-��

��Y

'�!���)

����(#�WV&*�

��.��� Attribute

3. Multivalued Attribute ���*-S! � %�3$3�0�%&������-�&()����*� � 2 � ����S�!�������-�&�T\3,��ZS,W�()����*��)�$ 2 � #�3HH�0�&,B%, , #.�0�� ��� ��,ZS,W���S�!�� �'�&$ ��B%�Z�%�()����*$ �� B)*'�"2��!�&� !�!]� �,���%�� %�3$3�0�%&��&���*� �

��,!��

����

2�� %&� *�

,��ZS,W�

� %�3$3�0�%&��&���*� �

14/06/56

8

���)�)�*$�%&�%� �'(��

��,!��

����

2�� %&� *�

,��ZS,W� 1

,��ZS,W� 2

,��ZS,W� 3

0�� * �!�� ���%&�,3)'�,,���#�!� %�3$�0�%&��&���*� �(##.�� %�3$3�0�"�� ()����*0��� ���(#����!�� ���"�0���!

��.��� Attribute• 4. Derived attribute �� � %�3$3�0�%&�()���'�,,�������V

'�,� %�3$3�0� ��� B)*%���(#(� 0� !'�),K$� %�3$3�0��&I 2 � � %�3$3�0� �*T ��� !'�,�����-�����V()�'�,���)� �#_,3) ��� * )���� !"$��K'�0 ��"$ �����V()�'�,��*,���3����"�"$��K' #.�0��

• "��X�Y� ER '�"2����#��%� derived attribute

��,ZS,W�����

2��

�V� Z���)� �#_,3)

�*T

14/06/56

9

��.��� KeyR B)*%���(#'�0� !�& * �!�� * 1 Attribute ��� ��,,� � %&�%��"���� ����0 ���-�

��� �� ��)�&�����0,0 �!,��R 0�� * �!2 �

b ��,ZS,W��0 �����&����#��'��0��%&�(� ]I��,�� ����#��'��0����,ZS,W� 'S!�&*,� � �&*�

R �$ ! ,()� 2 * �! �� b Simple Key �� �&� %%�3$3�%� 1 � %%�3$3�%�%&�#.��&*�b Composite Key �� �&*�#��, $ %&��&� %%�3$3�%���,,� � 1 � %%�3$3�%�%&�#.��&*�

R ��H��,WV� �%�)��* �&)���"0�� %%�3$3�%�%&�#.��&*�

Simple Key

Composite Key

StudentCode

Name

Address GenderTel

DOB

SellingBillNo

Prod_ID

Qty SalePriceSaleDate

Cust_ID

14/06/56

10

9%��&��:��;* (Relationship)

� !"#$"%$&'( (Relationship) ���*-S!��������������� �! K�030&I ]S�!#.�(#0��2�3)� !����������� B)*�����������'������ )��*�0T,��V�%&�2�� �B*!"� K�%&0& B)*,��0�I!2�� �����������'�"2����,�3*�%&���)!,��,��%�� 2 � �&,� �,� �'��! #.�0��

9%��&��:��;* (relationship)

�!%�$&*�

• 0�� * �! Relationship ���� �! Entity ��,ZS,W� ,�$ Entity ��*�32� �&����������� �� ��,ZS,W��!%�$&*��&*�"���*�32���I� 1

• 0�� * �! ��,ZS,W�'��&�����������,�$�����32�%&��3�30��!,�) *�

• '�"2���H��,WV� �&���&�*���������0�)�%� ����&,��0�I!2�� �������������I�,��,�$Y�*"� B)*2�� %&�,��,�$0� !#.����,3�3*�

��,ZS,W� �32�

��!,�)��,ZS,W� �V�

14/06/56

11

,��-@���9%��&��:��;* (Relationships & Entity Set)

��)�$� ! relationship '���)!)��*'������ ! Entity %&��������,�� ��

b Unary relationship #.������������%&��& Entity &*! Entity )&*�

b Binary relationship #.������������%&��& Entity ,&�*��� !)��* 2 Entity

b Ternary relationship #.������������%&��& Entity ,&�*��� !)��* 3 Entity

b Quaternary Relationship #.������������%&��& Entity ,&�*��� !)��* 4 Entity

A Unary Relationship

�32� 0� !�&*���, �

14/06/56

12

Binary Relationship

Student /0!�!%�$&*�

Ternary Relationship

��,!�� 0����� !%��!��

����

14/06/56

13

Quaternary Relationship

�G-�)H*�� Relationship

• Cardinality Constraints

• Participation Constraints

14/06/56

14

Cardinality Constraints

• #.�,�����0������,����)"������������� !�0 �� entity ()��,

b One-to-One (1:1)

b One-to-Many (1:N)

b Many-to-Many (M:N)

• "��X�Y� ER '��%�B)*,���&*�,��,�$%&����2�� ������������ �� �3$�*������������ ! �%&0&

Relationship Connectivity

&$12314! /0!56789:;<&

=!>!?<( /0!#=&

#"!0/1 ?@$#AB!&#"$�?1 1

1 N

M N

14/06/56

15

Participation Constraint

R !�� �(�,���&� ��� �� �� '�����0����T)� ! entity %&� &, entity ��S�!�&�����������)��* �& 2 �$$��

b Total Participation

R ,��%&� entity ��S�! entity '�0� !�&�����������,�$ entity ��� * �!�� *��&�! entity 2 � �'��*�%T,��0� !��!,�) * �!�� *"� ��&�!�V� #.�0�� ,���&� ��� ��%�I!��)'���)!)��*����� %�!)���2�3)� ! entity %&�%T, entity "�2�3)��I�0� !���� ��"������������

�'��*� ��!,�) �V�M 1

Participation Constraint(������������))))

b Partial Participation

R ,��%&�entity ��S�!entity �&�����������,�$entity ��� * �!�� *Z��*�entity �� "�2�3)� !entity )&*�,�� �'�&$�!entity %&��&� ��� ��"��������������I� "��V�%&�$�!entity %&�(� �&� ��� ��"��������������I��* 2 � �X�,$�!�X�,(� �&��,!����!,�)�* ���$�!�X�, �'�&��,!����!,�)���*��

R ,���&� ��� ��$�!� ��'���)!B)*"2����)&*�)���2�3)� !entity %&�$�!entity"�2�3)��I��&� ��� ��"������������ 2 � ���)&*�'�,entity �X�,

�'��*� ��!,�) �X�,M 1

14/06/56

16

Constraint

• � ,'�,�&I,��,����) constraint �����-,����)"���#�$$ (min,max) ()�

• 2 � -���&,��,����)� � �'��*�����S�!� �()�(� ,3� 3 �32� 0 Y��,��ZS,W� ��� ��,ZS,W������-�!%�$&*�()�(� ,3� 6 �32�0 Y��,��ZS,W�#.�0�� B)*�����-�&*�()�#.��X�Y�)�!�&I

��,ZS,W� �32��!%�$&*�

�'��*� �32�� �1 N

M N

(0,3) (1,n)

(1,6) (0,30)

14/06/56

17

Weak entity

@"!<H36 9=&7;I;7;JK"B#!"!?H91/LM3N&9=6KLO PL<Q?!2>!19=&7;I;7;J";� !"#$"%$&'(=<RB S58>8";�;<(@5$1>!11!?#T:7=L9=&7;I;7;J"$&%3J6%/6=<RB "!U0O9QV&�;<(@5$1@?T=#B &@&3J6M=6�;<(@5$1 PL< Weak Entity >8U0O#$Z5$14[(?RQ#;J9@5;J<"AT&AO!SIB9QV&9#O&�RB I$ =<B!690B&

Weak Entity

R ������� �%30&I��,!����� �030&IH�03 -��(� �& �030&I��,!�� �030&IH�03,K'�(� ,3)�SI�b �030&IH�03 #.� Weak Entity

b �030&I��,!�� #.� Entity

��,!�� �& H�031 M

-H�03 #.� weak entity %&�(� �& primary key B)*�TV��$�03 ���)�$%&� �&� �]I��,��"��&�2��� H�03 ����TV��$�03 ���)�$%&� �&� �]I��1 ,��()�"����*H�03 2 � ���)�$%&� 1 #.�H�03 ��*��� ������)�$%&� 1 #.�H�03 ��*�)!

-qrs!2�3)� !entity H�03 #.��$$ Total Participation

���)�$%&�������,!��

14/06/56

18

����&��-���$/$������ (Weak entity)

����+������ ��& �0��

1001 ��*��2�* "')& ,��0��)

1002 ��!tu�"� �3��� $�H2&

1003 ��*�)T)& ��$��V� ,��0��)

����+������ ������%& !�*)

1001 1 ��!��Z�& "')&

1001 2 ).2.2�Z�,)3v "')&

1002 1 ��* ! �' �3���

Weak Entity

�32�

#w)� �

�32�%&�#w)� �

1

M

�����32�

2�� �32�

����,��#w)� �

����&*�

#_-Y��

,�T �

14/06/56

19

Recursive Relationship

• #.� �%&0&%&�,3)'�, �%&0&&*! �%&0&)&*� %&��&*,� �������������$$*����& ]S�! �'#.��$$ 1:1 , 1:M , M:N ,K()� 2 � ����������� ��,!��%&�#.�X��$�3��� ]S�!��S�!�� �''�$�3�����,!��()����*�� (X��$�3���,K#.���,!��2 �)&*�,��)

��,!��

$�3���

1 M

��,!��

�0 !!��

1 1�32�

�&*���, �

M N

14/06/56

20

����+������ ��& �����1 (������

001 ��'���' �1����&� 002

002 ����)��� �1����&� 001

003 ��'���� �)�+��

004 ������!)� E��)�)*) 015

/�%�N�����9*,������O�@�:��������� E-R

2�� � %�3$3�0�

������,ZS,W��&*����,

� %�3$3�0����*� �

�*T)&(�t)�� %�3$3�0�

��,ZS,W�

��,ZS,W�

�0 !!��

�%&0&

�%&0& ��

�&�2��23

���23,

2��

14/06/56

21

/�%�N�����9*,��������O�@�:��������� E-R

Customer Rents Videotape

balance

lastName

accountID

title

Videotape_ID

genre

1 M

address

otherUsers

numberRentals

FirstName

street zipcode

cityCardinality

RelationshipKey attribute

Multivalued attribute

Attribute

Compositeattribute

Derivedattribute

������������� �������(���()�

• ,����)� ��& Entity �(�$��!

• ,����)��������������� �! Entity

• ,����) Attribute � ! Entity "����$

• 3'��V� Attribute %&��SI�,�$ Relationship

• �� , Identifier ��� Primary Key

14/06/56

22

���� ������� �(������+��,$����������)*%'������ ���*����������

Department Manage Supervisor1 M

Department (Dept num, Dept_name, Loc)

��I��� 0���!�X�, (Department) #��, $)��* Attribute 0 �!1 )�!�&I �����X�, (Dept_num), 2�� �X�, (Dept_name) #.��&*����,

Supervisor(Sup code, Sup_name, Sup_age, Sup_sex, Dept_num)

��I��� 0���!������� (Supervisor) #��, $)��* Attribute 0 �!1 )�!�&I ����������� (Sup_code) ]S�!#.��&*����, 2�� ������� (Sup_name) �*T������� (Sup_age) ���Z� !������� (Sup_sex)

*��'���(������+��,$����������)*%

Faculty offers Course1 M

Lecturer teaches section1 M

Student

enroll

RoomM M

is assigned to

advises

has

generates

uses

M

M

MM

M

1

1

1

1

N1

14/06/56

23

Thank you for your attention!