บทที่ 5 การแปลง er diagram ให้เป็น table

21
1 ระบบฐานข้อมูล การแปลง ER - Diagram ให้เป็ น Table หน่วยการเรียนที่ 5

Upload: -

Post on 24-Jun-2015

5.219 views

Category:

Documents


3 download

TRANSCRIPT

1ระบบฐานขอมล

การแปลง ER-Diagram ใหเปน Tableหนวยการเรยนท 5

2ระบบฐานขอมล

การเปลยนจาก E-R Schema ใหอยในลกษณะ Tables

Primary keys ของ entity sets และ relationship sets สามารถน ามาเปนPrimary keys ของ tables ไดเลย

แตละ entity set จะถกแปลงเปน table ซงมชอของ table ตามชอของ entity

โดยทวไป แตละ table จะมจ านวนคอลมนตามจ านวน Property ของ Entity

3ระบบฐานขอมล

การแปลงจาก Entity Sets เปน Tables

Strong entity set เปลยนเปน table ไดเลย โดยม attributes ตาม Property ของ Entity

EMPLOYEE

EmpID NAME SEX SALARY

EmpID Name Sex SalaryEmployee

Employee (EmpID, Name, Sex, Salary)

4ระบบฐานขอมล

การแปลงจาก Entity Sets เปน Tables

Composite Property ใหน าแตละ Property ยอย มาก าหนดเปน Attributeใน table เลย

EMPLOYEEEmpID

NAME SEX SALARYFNAME

SNAME

EmpID FName SName Sex SalaryEmployee

Employee (EmpID, FName, SName, Sex, Salary)

5ระบบฐานขอมล

การแปลงจาก Entity Sets เปน Tables multivalued Property จะน าคา Property ทเปน Multivalued แยกออกมาจาก

Entity เดม มาสรางเปน table ใหม

Primary Key ของ Table ใหมทสรางจะประกอบดวย Property ทเปนprimary key ของ entity เดม และ multivalued property

EMPLOYEEEmpID

NAME SEX SALARY

FNAME

SNAME

TEL_NUMBEREMPLOYEEEmpID

NAME SEX SALARY

FNAME

SNAME

TEL_NUMBER

EmpID FName SName Sex SalaryEmployee

Emp_Tel (EmpID, Tel_Number

EmpID Tel_NumberEmp_Tel

Employee (EmpID, FName, SName, Sex, Salary)Foreign Key

6ระบบฐานขอมล

การแปลง Weak Entity Sets เปน Table การแปลง Weak entity set เปน table ใหรวมเอา identifying ของ

strong entity set มาเปน primary key ของ table ดวย

Employee

EmpID

Name SexSalary

TimeHasM1

Date Time

EmpID FName SName Sex SalaryEmployee

EmpID Date TimeEmp_Time

Foreign Key

7ระบบฐานขอมล

การเปลยน Relationship Sets เปน Tables

ถาเปน many-to-many relationship set ใหน า primary key ของ ทง 2 entity ทมความสมพนธกน มาเปนคา primary key ของ table ใหม หากม property ของ relationship set กน ามาเปน attribute ของ table ดวย

STUDENT

SID SNAME

COURSE

CID CNAME

TAKE

GRADE

STUDENT

SID SNAME

COURSE

CID CNAME

TAKE

GRADE

M M

SID SNameStudent

SID CID GradeTake

CID CNameCourse

8ระบบฐานขอมล

การเปลยน Relationship Sets เปน Tables

Many-to-one และ one-to-many relationship sets ใหเพม attribute ทเปนคา primary key ของ Entity ดาน one เขาไปใน Entity ดาน many

one-to-one relationship sets สามารถเพม attribute เขาไปทขางใดของ relationship กได

EMPLOYEEEmpID

NAME SEX SALARY

DEPARTMENT

DEP_ID DEP_NAME

WORK_INM 1

EmpID Name Sex Salary Dep_IDEmployee

Dep_ID Dep_NameDepartment

9ระบบฐานขอมล

การแปลง Relationship แบบ Recursive เปน Table

EmpID Name Sex Salary Manager_IDEmployee

EMPLOYEE

EmpID NAME SEX SALARY

MANAGE_OF

EMPLOYEE

EmpID NAME SEX SALARY

EMPLOYEE

EmpID NAME SEX SALARY

MANAGE_OF

M1

10ระบบฐานขอมล

การแปลง Relationship แบบ Recursive เปน Table

Item_No Name Unit_CostItem

Item_No Component_No QuantityComponent

EMPLOYEE

EmpID SALARY

Contains

EMPLOYEE

EmpID SALARY

Item

Item_No Name Unit_Cost

MM

Quantity

11ระบบฐานขอมล

Implementation of the M:N Recursive “PART Contains PART” Relationship

12ระบบฐานขอมล

การเปลยน Specialization เปน Tables

EMPLOYEE

NAME SEX SALARY

MALE FEMALE

MILITARY_STATUS

Person

NAME Street City

Customer Employee

Salary MILITARY_STATUSCredit-Rating

13ระบบฐานขอมล

การเปลยน Specialization เปน Tables วธท 1:

สราง table ส าหรบ higher level entity set

สราง table ส าหรบแตละ lower level entity set, โดยน า primary key ของ higher level entity set มารวมทง local attributes ของ entity

table table attributesperson name, street, city customer name, credit-ratingemployee name, salaryขอดอย: หากตองการขอมลเชน ขอมลของ employee ตองไปดงขอมลจาก 2

tables มา

14ระบบฐานขอมล

วธท 2:

สราง table ส าหรบแตละ entity set ดวย property ของ Superset และ Subset entity

table table attributesperson name, street, citycustomer name, street, city, credit-ratingemployee name, street, city, salary

ถา specialization เปน total, กไมจ าเปนตองสราง table ของ Superset (person)

ขอดอย: ในกรณทมบคคล ทเปนทง customers และ employees จะเกด redundantly ของ street และ city

การเปลยน Specialization เปน Tables (ตอ)

15ระบบฐานขอมล

ค าศพท

binary relationship cardinality

composite attribute degree

derived attribute disjoint subtypes

existence-dependent existence-independent

mandatory multivalued attribute

optional overlapping subtypes

participation recursive relationship

16ระบบฐานขอมล

ค าศพท

simple attribute single-valued attribute

strong relationship subtype

supertype ternary relationship

unary relationship weak entity

weak relationship

17ระบบฐานขอมล

workshop

ปรบปรง ERD ใหสมบรณ

EmpID

EmpNameEducation

Employee

DeptID

DeptIDDName

Detail

DepartmentIN

M 1

18ระบบฐานขอมล

workshop

ปรบปรง ERD ใหสมบรณ

Customer BookRentM N

19ระบบฐานขอมล

ออกแบบ ERD จากเอกสารตอไปน

/

777/7 .1 . . . 20280 038-288822-30 038-288831 x xxx xxxxx x

555/5 .8 . .

IVxxx-xxxx 11/09/2547 30 10/10/2547 xxxxxxx

/

1 xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxx 30 xxxx xxxx

2 % 7.00%

Remark :

75,000.001,500.00

73,500.005,145.00

78,645.00 ( )

………………………… ……./……./……..

………………………………….

2 xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxx 30 xxxx xxxx

20ระบบฐานขอมล

Workshop

ออกแบบฐานขอมลส าหรบอซอมรถยนต เพอเกบขอมลตางๆ ดงน

ขอมลชางในอ เชน ขอมลสวนตว ความถนด ประสบการณ ฯลฯ

ขอมลรถยนตทเคยมาซอม (รถยนตแตละคนมเจาของไดหลายคน)

ขอมลลกคาทเคยมาซอม (ลกคาแตละคนมรถยนตไดหลายคน)

ขอมลประวตการซอม โดยจะตองสามารถตรวจสอบขอมลการซอมไดวาซอมอาการเสยอะไรบาง และมชางคนใดเปนผรบผดชอบการซอม มการเปลยนอะไหล อะไรบาง ฯลฯ ในการซอมแตละครง สามารถมชางรวมกนซอมไดหลายคน

เกบขอมลเกยวกบอะไหลรถยนต

21ระบบฐานขอมล

ออกแบบฐานขอมลพนกงานตอไปน

จดเกบขอมลประวตสวนตวของพนกงาน และขอมลอนๆดงน

ประวตการศกษา

ประวตการฝกอบรม

ประวตการถกลงโทษ

ประวตการไดรบรางวล

ประวตการเลอนต าแหนงงานในองคกร

เกบขอมลบคคลอางอง โดยพนกงาน 1 คน มบคคลอางองไดหลายคน บคคลอางอง สามารถอางองใหกบพนกงานไดหลายคน