1 / 16

CHỦ ĐỀ 1: MÔ HÌNH ER VÀ CSDL QUAN HỆ

CHỦ ĐỀ 1: MÔ HÌNH ER VÀ CSDL QUAN HỆ. Một Ví dụ Ñaëc taû vaán ñeà

Download Presentation

CHỦ ĐỀ 1: MÔ HÌNH ER VÀ CSDL QUAN HỆ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHỦ ĐỀ 1: MÔ HÌNH ER VÀ CSDL QUAN HỆ

  2. Một Ví dụ • Ñaëc taû vaán ñeà • Nhöõng ngöôøi phuï traùch ñaøo taïo cuûa Tröôøng cao ñaúng coäng ñoàng nuùi Ayers mong muoán taïo laäp moät CSDL veà caùc moân ñaøo taïo cuûa tröôøng (nhö: chöùng chæ leo nuùi, coâng ngheä bay) vaø hoïc vieân ghi danh vaøo nhöõng moân hoïc naøy. Tröôøng cuõng coù qui ñònh laø cuøng moät luùc, hoïc vieân chæ coù theå ghi danh vaøo moät moân hoïc. Hoï chæ quan taâm veà döõ lieäu cuûa ñôït ghi danh hieän taïi. Moät khi hoïc vieân keát thuùc moân hoïc thì nhaø tröôøng seõ khoâng coøn quan taâm ñeán hoï vaø nhöõng hoïc vieân naøy phaûi ñöôïc xoùa khoûi CSDL. Thoâng tin caàn löu tröõ veà moät hoïc vieân bao goàm: maõ hoïc vieân, teân hoïc vieân, ñòa chæ, ngaøy sinh, soá ñieän thoaïi, ngaøy nhaäp hoïc • Thoâng tin veà moân hoïc goàm maõ moân hoïc, teân moân hoïc, thôøi löôïng • Phaân tích: • phaàn ñaëc taû vaán ñeà chöùa ñöïng caùc qui taéc quaûn lyù vaø döõ lieäu yeâu caàu cuûa vaán ñeà. • Thực thể : HỌC VIEÂN, MOÂN HOÏC • Nhöõng thuoäc tính HOÏC VIEÂN coù maõ hoïc vieân, teân hoïc vieân, ñòa chæ, ngaøy sinh, soá ñieän thoaïi vaø MOÂN HOÏC coù maõ moân hoïc, teân moân hoïc ,ø thôøi löôïng. • qui taéc quaûn lyù goàm: • Cuøng moät luùc, moät hoïc vieân chæ coù theå ghi danh vaøo moät moân hoïc. • Nhieàu hoïc vieân coù theå ghi danh vaøo moät moân hoïc. • Nhaø tröôøng chæ quan taâm ñeán nhöõng hoïc vieân cuûa moân hoïc hieän taïi.

  3. Moâ hình ER cho ví duï

  4. Nhöõng böôùc xaây döïng moâ hình ER Xaùc ñònh nhöõng thöïc theå chính vaø khoùa Coù Identifier, nhieàu theå hieän, coù ít nhaát moät thuoäc tính, coù ít nhaát moät moái lieân keát. Noù thöôøng laø danh töø MOÂ HÌNH ER Xaùc ñònh moái lieân keát giöõa nhöõng thöïc theå Veõ ñöôøng lieân keát , xaùc ñònh baûn soá 1-1, 1-M, M-Mù.Theâm thöïc theå lieân keát ñeå phaù vôõ lieân keát M-M Theâm vaøo nhöõng thuoäc tính cuûa thöïc theå Nhöõng tính chaát rieâng cuûa thöïc theå

  5. EXERCISE Northern Hardware Wholesalers (NHW) operates a warehouse which distributes stock to a chain of hardware stores. The company purchases stock item from a variety of suppliers. Stock details to be stored are stock number (unique) and description. The company also needs to store supplier code (unique), name, address and telephone and fax numbers. The business must be competitive, so it sources the same product from different suppliers, each of which can deliver a maximum quantity of that stock item. The stock items are stored in bins in the warehouse. Each bin has a unique ID and size. Sometimes the allocated bin is too small to hold the entire (toàn bộ) quantities of a product (for example, you cannot fit a struck into one bin), so more than one bin will be allocated. However, there is never more than one type of stock item stored in the same location. Develop an ER diagram for this problem.

  6. solution supplier code stock number max quantity stock number description available for STOCK ITEM MAXIMUM SUPLIER of contains can supply stored in purchase from BIN SUPPLIER binID size Supplier code name address phone# tax#

  7. Vị trí khóa ngoại trong quan hệ Ví duï 1: moái lieân keát baét buoäc töø 2 phía Qui luaät nghieäp vuï: Moãi nhaân vieân phaûi duøng moät xe cuûa coâng tyvaø moãi xe do moät nhaân vieân söû duïng. Car Employee Employee (Employee#, EmployeeName, Registration#) Car (Registration#, Make) **Chuù yù: Khoaù ngoaïi ñaët beân quan heä naøo tuùy yù

  8. Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 2: moái lieân keát baét buoäc töø 1 phía Qui luaät nghieäp vuï: Moãi nhaân vieân coù theå duøng moät xe cuûa coâng ty vaø moãi xe do moät nhaân vieân söû duïng. Employee Car Employee (Employee#, EmployeeName) Car (Registration#, Make, Employee#) **Chuù yù: Khoaù ngoaïi ñaët beân quan heä baét buoäc

  9. Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 3: moái lieân keát khoâng baét buoäc töø 2 phía Qui luaät nghieäp vuï: Moãi nhaân vieân coù theå duøng moät xe cuûa coâng ty vaø moãi xe coù theå do moät nhaân vieân söû duïng. Car Employee EmployeeCar Employee (Employee#, EmployeeName) Car (Registration#, Make) EmployeeCar (Employee#, Registration#) **Chuù yù: coù 3 quan heä ñöôïc xaây döïng

  10. Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 4: moái lieân keát baét buoäc töø phía nhieàu Qui luaät nghieäp vuï: Moãi khoa coù theå coù 0,1 hay nhieàu beänh nhaân nhöng moãi beänh nhaân thuoäc veà moät khoa. Patient Ward Ward (WardName, WardType) Patient (Patient#, PatientName, WardName) **Chuù yù: khoaù ngoïai ñaët beân nhieàu

  11. Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 5: moái lieân keát khoâng baét buoäc töø phía nhieàu Qui luaät nghieäp vuï: Moãi khoa coù theå coù 0,1 hay nhieàu beänh nhaân nhöng moãi beänh nhaân coù theå thuoäc veà moät khoa. Patient Ward WardPatient Ward (WardName, WardType) Patient (Patient#, PatientName) WardPatient (Patient#, WardName) **Chuù yù: ba quan heä ñöôïc thaønh laäp

  12. Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 6: moái lieân keát nhieàu- nhieàu Qui luaät nghieäp vuï: Moãi sinh vieân coù theå ghi danh 0,1 hay nhieàu moân, moãi moân coù theå coù 0,1 hay nhieàu sinh vieân. Student Subject StudentSubject Student (Student#, StudentName, StudentAddress) Subject (Subject#, SubjectName, Department) StudentSubject (Student#, Subject#) **Chuù yù: thöïc theå coù khoùa lieân keát

  13. Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 7: Moái lieân keát ñeä qui 1-1 Qui luaät : moät ngöôøi coù t Vị trí khóa ngoại trong quan hệ (tieáp theo)heå keát hoân vôùi 0 hay 1 ngöôøi Ngöôøi ta thöôøng bieåu thò moái lieân keát naøy baèng moät baûng ñôn. Person (Person#, SpousePerson#, ..............................) Tuy nhieân, bieåu thò nhö theá, khoâng theå phaân bieät ñöôïc nhöõng ngöôøi choàng vaø nhöõng ngöôøi vôï. Do ñoù coù theå bieåu thò baèng 2 baûng nhö : Person (Person#, .......................) Marriage (HusbandPerson#, WifePerson#)

  14. Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 8: Moái lieân keát ñeä qui 1-M: Ñaây laø moät ví duï cuï theå cho caøi ñaët moät caáu truùc thöù baäc trong moâ hình döõ lieäu quan heä Qui luaät : moät nhaân vieân coù theå bò giaùm saùt bôûi 0, 1 hay nhieàu nhaân vieân. Moãi nhaân vieân coù theå giaùm saùt 0, 1 hay nhieàu nhaân vieân Tröôøng hôïp naøy ñöôïc bieåu thò baèng moät baûng ñôn Employee (Employee#, SupervisorEmployee#, .................)

  15. Part1 Part2 Part3 Part4 Part5 Part6 Part7 Vị trí khóa ngoại trong quan hệ (tieáp theo) Ví duï 9: Moái lieân keát ñeä qui M:M.Ñaây laø tröôøng hôïp cho ví duï cuï theå caøi ñaët caáu truù maïng treân moâ hìnhdöõ lieäu quan heä Qui luaät: Moät boä phaän ñöôïc saûn xuaát bao goàm nhieàu boä phaän khaùc. Coi ví duï: Part MajorComponent Bieåu thò baèng 2 quan heä Part (Part#, Description, Location, ................) MajorComponent (MajorPart#, ComponentPart#)

  16. TOÅNG KEÁT

More Related