mapping in database

34
Mapping ت ش گا ن: ه عادل ل ل ا ت م ص ع ده ن ن ک ه ی ه ت

Upload: esmatullah-adel

Post on 16-Apr-2017

204 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Mapping in database

Mapping

نگاشت

: عادل الله عصمت کننده تهیه

Page 2: Mapping in database

07:05 PM Gharjistan University Computer Science Faculty Farah Branch

2

Topics:

• Transformation EER diagram in relations:

• Map regular entities• Map weak entity• Map binary relationships• Map associative entity• Map unary relationships• Map ternary relationships• Mapping supertype/subtype relationships

دیاگرام • جدول EERتبدیل بهها

عادی • موجودیت نگاشتضعیف • موجودیت نگاشتدوگانه • ارتباط نگاشتشرکت • موجودیت نگاشت

پذیریگانه • ارتباط نگاشتگانه • سه ارتباط نگاشت

نمونه • ارتباط نگاشتفرعی/ اصلی

Page 3: Mapping in database

Computer Science Faculty, Database1 3

Transformation EER diagram in relations:

• In this we will convert ER and EER diagrams that were developed in conceptual design into Relational database schemas.

• By using the following steps:

تبدیل • پروسه از عبارتهای دیاگرام EERو ERنمودن

مفهومی) دیزاین در که ) ها جدول به بود شده ساخته

میباشد.•: ذیل مراحل استفاده با

Page 4: Mapping in database

Computer Science Faculty, Database1 4

1. Map regular entities:

• Each regular entity type in an ER Diagram is transformed into a relation.

• Name same as to entity name.

• Attributes become attributes of relation.

• Identifier become Primary key.

در • عادی موجودیت نوع هردیاگرام جدول ERیک یک به

. میشود تبدیلیک • موجودیت نام با آن نام

. میباشد چیزموجودیت • خاصه صفات

قرار جدول خاصه صفاتمیگیرد.

جدول • اصلی کلید شناسه،میشود.

Page 5: Mapping in database

07:05 PM Gharjistan University Computer Science Faculty Farah Branch

5

Continue…

Page 6: Mapping in database

Computer Science Faculty, Database1 6

In case of composite attributes:

• When any entity have composite attributes ,only the simple component attributes of the composite attribute are included in the new relation.

صفات • موجودیت یک وقتیکهباشد، داشته را مرکب خاصه

جزئی خاصه صفات فقطرا مرکب خاصه صفت ساده. میسازیم جدید جدول شامل

Page 7: Mapping in database

Computer Science Faculty, Database1 7

In case of composite attributes…

Page 8: Mapping in database

Computer Science Faculty, Database1 8

Multi value attribute:

• When a regular entity type contains a multi valued attribute, two new relations are created .

• First Relation contain all of the attributes of the entity type except the multi valued attribute.

• Second Relation contain primary key ,plus its attribute.

موجودیت • نوع یک زمانیکهخاصه صفت دارای عادی

پسدو باشد قیمته چندین. میشود ساخته جدید جدول

صفات • تمام اول جدولاز بجز موجودیت خاصه

را قیمته چند خاصه صفت. بوده داراء

اصلی • کلید شامل دوم جدولچند خاصه صفت اضافه با

. میباشد قیمته

Page 9: Mapping in database

Computer Science Faculty, Database1 9

Multi value attribute…

Page 10: Mapping in database

Computer Science Faculty, Database1 10

2. Map weak entity:

• Weak entity has no independence existence ,but exists only through an identifying relationship with another entity type called the owner.

a) For each weak entity create a relation associate its attributes.

وجود • هیچ ضعیف موجودیتمیتواند اما نداشته، مستقل

قوی موجودیت توسط. شود موجود

)a ضعیف موجودیت هر برایتمام و بسازید را جدول یکرا موجودیت خاصه صفاتجدول های ستون منحیث

. دهید قرار

Page 11: Mapping in database

Computer Science Faculty, Database1 11

2. Map weak entity…

b) Include the primary key of the identifying relation as a foreign key attribute in this new relation.

• For example: Driver ,,,,license

• When driver die its license finish automatically.

)b قوی موجودیت اصلی کلیددر خارجی کلید منحیث را

. دهید قرار جدید جدول• : لسانس و راننده مثال بطورمیرد • می راننده زمانیکه

. میکند پیدا خاتمه آن لسانس

Page 12: Mapping in database

Computer Science Faculty, Database1 12

3. Map binary relationship:

• Binary relationship is mapped according to its cardinalities.

1. Mapping binary 1:M relationships:

• First create two tables for each entity.

براساس • دوگانه ارتباطآن .mapکاردینالیتی میشود

دوگانه 1. ارتباط نگاشت: چند به یک

هر • برای را جدول دو ابتدا. کنید درست موجودیت

Page 13: Mapping in database

Computer Science Faculty, Database1 13

3. Map binary relationship…

• Next include the primary key attribute of the entity on the one side of the relationship as a foreign key in the relation that is on the many side of the relationship.

• Example as of customer and order.

موجودیت • اصلی کلید سپسارتباط یگانه سمت در ایکه

کلید منحیث دارد قراردر ایکه موجودیت خارجی

دارد قرار ارتباط چند سمت. دهید قرار

• : مثال و customerبطورorder

Page 14: Mapping in database

Computer Science Faculty, Database1 14

3. Map binary relationship…

Page 15: Mapping in database

Computer Science Faculty, Database1 15

3. Map binary relationship…

2. Map Binary M:M:• When two entities have

M:M relationship then we create a new relation C.

• This new relation contains primary key of both Relations (A and B).

دوگانه • ارتباط نگاشت: چند به چند

ارتباط • موجودیت دو زمانیکهباشد داشته چند به چند

جدید جدول یک ما Cسپس. میسازیم را

کلید • شامل جدید جدولجدول دو هر Bو Aاصلی

میباشد.

Page 16: Mapping in database

Computer Science Faculty, Database1 16

3. Map binary relationship…

Page 17: Mapping in database

Computer Science Faculty, Database1 17

3. Map binary relationship…

• Map binary 1:1 Relation:• Create two relations for

each entity.• Put primary key of

Mandatory one side in optional side.

دوگانه • ارتباط نگاشت: یک به یک

جدول • یک موجودیت هر برای. کنید درست را

اجباری • یک سمت اصلی کلیدسمت خارجی کلید منحیث را

. دهید قرار اختیاری یک

Page 18: Mapping in database

Computer Science Faculty, Database1 18

3. Map binary relationship…

Page 19: Mapping in database

Computer Science Faculty, Database1 19

4. Map associative entity:

• Associative entity is mapped like a many to many binary relationship.

• Create three tables.• Third for associative entity.• An identifier is assigned to

the associative relation.

مانند • پذیر شرکت موجودیتچند به چند دوگانه ارتباط

. میشود نگاشته•. بسازید را جدول سهموجودیت • برای سوم جدول

. پذیر شرکتشرکت • جدول به شناسه یک

. میشود تعیین پذیر

Page 20: Mapping in database

Computer Science Faculty, Database1 20

4. Map associative entity…

Page 21: Mapping in database

Computer Science Faculty, Database1 21

4. Map associative entity…

Page 22: Mapping in database

Computer Science Faculty, Database1 22

Continue…

• Sometimes the data modeler assign an identifier called surrogate identifier, to the associative entity type on ER Diagram.

دیتا • ساز مدل اوقات بعضینوع به را شناسه یک

تعیین پذیر شرکت موجودیتشناسه بنام که میکند

. میشود یاد جایگزین

Page 23: Mapping in database

Computer Science Faculty, Database1 23

Continue…

Page 24: Mapping in database

Computer Science Faculty, Database1 24

5. Map Unary Relationships:

• Also called recursive relationship.

• The two most important cases are:

1. One to many2. Many to Many• A relation is formed for entity.• Then a foreign attribute is

added within the same relation that references the primary key value.

بنام • همچنان یک درجه ارتباط. میشود یاد بازگشتی ارتباط

•: دارد حالت سهیک • به یکچند • به یک

Page 25: Mapping in database

Computer Science Faculty, Database1 25

Continue…

1. Unary one to many relationship:

• The entity type in the unary relationship is mapped to a relation.

• Then a foreign key attribute is added to the same relation that references the primary key values in the same relation.

درجه • چند به یک ارتباطیک:

درجه • ارتباط در موجودیت نوعنگاشته جدول یک به یک

میشود.

شناسه • خاصه سپسصفتاضافه جدول عین به خارجی

کلید های قیمت به که شدهمرجع جدول خود در اصلی

میدهد.

Page 26: Mapping in database

Computer Science Faculty, Database1 26

Cont…

Page 27: Mapping in database

Computer Science Faculty, Database1 27

Continue…

• Unary M:M Relationship:• Two relations are created,

one for entity and other is an associative relation.

• The primary key of associative relation consist of two attribute.

• Example:

•: یک درجه چند به چند ارتباطیکی • میشود ساخته جدول دو

دیگری و موجودیت نوع برای. پذیر شرکت جدول برای

شرکت • جدول اصلی کلیدخاصه صفت دو شامل پذیر

میباشد.•: مثال بطور

Page 28: Mapping in database

Computer Science Faculty, Database1 28

Cont…

Page 29: Mapping in database

Computer Science Faculty, Database1 29

6. Map Ternary Relationships:

• Convert ternary relationship to an associative entity.

• Create a relation for the associative entity.

• Its Primary key may consist of 3 foreign keys.

یک • به را سه درجه ارتباطتبدیل پذیر شرکت موجودیت

کنید.موجودیت • برای را جدول یک

. بسازید پذیر شرکتمرکب • ممکن آن اصلی کلید

. باشد خارجی کلید سه از

Page 30: Mapping in database

07:05 PM Gharjistan University Computer Science Faculty Farah Branch

30

Continue…

Page 31: Mapping in database

07:05 PM Gharjistan University Computer Science Faculty Farah Branch

31

7. Map super type/subtype relations:

• Create a separate relation for the super type and for each of its sub types.

• Assign the attributes that are common to all members of the super type, including the primary key to the relation created for the super type.

برای • جدا جدول superیکtype از یک هر برای subوtype. بسازید ها

برای • ایکه جدول superبهtype شده attributeساخته

تمام بین که بدهید را هایsub type هستند مشترک ها

. اصلی کلید شمول به

Page 32: Mapping in database

07:05 PM Gharjistan University Computer Science Faculty Farah Branch

32

Continue…

• Assign the primary key of the super type and only those attributes that are unique to the sub type to the relation for each sub type.

• Assign one (or more) attributes of the super type to function as the sub type discriminator.

از • یک هر برای ایکه جدول بهsub type میشود ساخته ها

اصلی و super typeکلیدمربوط attributeفقط هایکه

همان است sub typeبهبدهید.

تفکیک • منحیث ایکه تابع بهیا sub typeکننده و یک بوده

خاصه صفت یک از بیشترsuper type. بدهید را

Page 33: Mapping in database

Computer Science Faculty, Database1 33

Continue…

Page 34: Mapping in database

07:05 PM Gharjistan University Computer Science Faculty Farah Branch

34