Bài giảng Hệ quản trị cơ sở dữ liệu - Chương 2: Mô hình thực thể kết hợp

46 9 0
Bài giảng Hệ quản trị cơ sở dữ liệu - Chương 2: Mô hình thực thể kết hợp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Mô hình hóa cơ sở dữ liệu bằng cách sử dụng kỹ thuật đồ họa để biểu diễn các đối tượng và quan hệ giữa các đối tượng trong thế giới thực mà con người có thể hiểu một cách dễ dàng. Trong chương này sẽ giới thiệu đến người học mô hình thực thể kết hợp, đây là một mô hình dựa trên thế giới thực trong đó bao gồm một tập các đối tượng gọi là thực thể và mối quan hệ giữa các thực thực thể. Mời các bạn cùng tham khảo.

CHƯƠNG 2: MƠ HÌNH THỰC THỂ KẾT HỢP (Entity Relationship Model -ER) Giới thiệu • Mơ hình hóa sở liệu cách sử dụng kỹ thuật đồ họa để biểu diễn đối tượng quan hệ đối tượng giới thực mà người hiểu cách dễ dàng • Mơ hình thực thể quan hệ (Entity Relationship) dựa giới thực bao gồm tập đối tượng gọi thực thể mối quan hệ thực thực thể Các bước thiết kế CSDL • Bước 1: Tập trung phân tích yêu cầu người dùng • Bước 2: Tạo lược đồ khái niệm cho CSDL cách sử dụng mơ hình liệu khái niệm mức cao (high-level conceptual data model) – Lược đồ khái niệm mô tả ngắn gọn yêu cầu người dùng mô tả chi tiết loại thực thể, mối quan hệ loại thực thể ràng buộc Các bước thiết kế CSDL • Bước 3: Hiện thực sở liệu sử mơ hình sở liệu quan hệ mơ hình sở liệu hướng đối tượng – Bước gọi thiết kế logic ánh xạ mơ hình liệu – Kết bước lược đồ sở liệu thực sở liệu hệ quản trị sở liệu • Bước cuối giai đoạn thiết kế vật lý – Xác định cấu trúc lưu trữ, cách truy cập liệu – Các chương trình ứng dụng thiết kế thực Các bước thiết kế CSDL Ví dụ CSDL Company • Các yêu cầu: – Công ty (Company) tổ chức thành phận (DEPARTMENTs) Mỗi phận có thông tin: Tên, Số, nhân viên người quản lý phận (MANAGER), sở liệu phải lưu thơng tin ngày mà nhân viên bắt đầu quản lý phận – Mỗi phận thực số dự án (PROJECTs) Mỗi dự án có Tên dự án, Mã số dự án vị trí dự án Ví dụ CSDL Company –Mỗi nhân viên (EMPLOYEE) có Mã nhân viên, địa chỉ, phái, lương, ngày sinh –Mỗi nhân viên làm việc cho phận tham gia nhiều dự án,trong sở liệu cần lưu thông tin số nhân viên làm việc dự án thông tin người giám sát nhân viên –Mỗi nhân viên có số người phụ thuộc (DEPENDENTs) Mỗi người phụ thuộc có thơng tin Tên, Phái, Ngày sinh mối quan hệ với nhân viên Entity Types, Entity Sets, Attributes, keys • Mơ hình ER mô tả liệu dạng thực thể (Entity), mối quan hệ (Relationships) thuộc tính (Attributes) – Thực thể (Entity): đối tượng tồn độc lập với đối tượng khác Ví dụ: người, vật … – Loại thực thể (Entity type): Là tập thực thể có thuộc tính – Thể thực thể (Entity instance ): thực thể đơn tập thực thể Entity Types, Entity Sets, Attributes, keys • Ví dụ: – SINHVIEN loại thực thể (entity type), – Một sinh viên cụ thể có Mã số sinh viên 555-555555 thể thực thể (Entity instance) – Tập hợp tất sinh viên loại thực thể (Entity set Entity type) • Trong mơ hình ER: – Mỗi loại thực thể (Entity type) có tên, thường danh từ – Trong mơ hình E-R, loại thực thể biểu diễn hình chữ nhật với tên đặt bên Entity Types, Entity Sets, Attributes, keys • Thuộc tính (Attribute): – Thuộc tính đặc điểm dùng để mô tả thực thể – Ví dụ: thực thể Nhân viên có thuộc tính Tên, Ngày sinh, Địa chỉ, Lương, … – Trong mơ hình E-R: thuộc tính biểu diễn hình ellipse kết nối với thực thể đường thẳng – Đối với thực thể, thuộc tính có giá trị xác định SSN Sex Employee 10 Relationships, Relationship Types 32 Relationships, Relationship Types • Ternary Relationships: mối quan hệ thể ba loại thực thể khác – Mỗi thể quan hệ ternary yêu cầu tham gia thể loại thực thể tham gia 33 Relationships, Relationship Types 34 Relationships, Relationship Types • Thuộc tính mối quan hệ (Attributes of Relationships): – Thuộc tính xác định kết hơp thực thể thể mối quan hệ 35 Relationships, Relationship Types • Thực thể kết hợp: loại thực thể mà liên kết với thể nhiều loại thực thể chứa thuộc tính tham gia kết hợp • Thực thể kết hợp quan hệ mà trở thành thực thể thuộc trường hợp sau: – Là mối quan hệ many-to-many nhị phân – Là quan hệ ternary quan hệ có bậc cao 36 Relationships, Relationship Types • Example: 37 Relationships, Relationship Types 38 Relationships, Relationship Types • Thực thể yếu (Weak Entity Types): loại thực thể khơng có thuộc tính khóa Ngược lại, thực thể có thuộc tính khóa gọi thực thể mạnh (strong entity types) – Thực thể mạnh tồn độc lập với loại thực thể khác, thực thể yếu phụ thuộc vào loại thực thể khác – Trong mơ hình E-R, thực thể yếu biểu diễn hình chữ nhật nét đơi, tương ứng, mối quan hệ thực thể yếu với thực thể chủ biểu diễn hình thoi nét đơi 39 Relationships, Relationship Types • Ví dụ: quan hệ Student Dependent 40 Mơ hình ER CSDL COMPANY • Specify the following relationship types: – MANAGES, a 1:1 relationship type between EMPLOYEE and DEPARTMENT EMPLOYEE participation is partial DEPARTMENT participation is not clear from the requirements We question the users, who say that a department must have a manager at all times, which implies total participation The attribute StartDate is assigned to this relationship type – WORKS_FOR, a 1:N relationship type between DEPARTMENT and EMPLOYEE Both participations are total – CONTROLS, a 1:N relationship type between DEPARTMENT and PROJECT The participation of PROJECT is total, whereas that of DEPARTMENT is determined to be partial, after consultation with the users 41 Mô hình ER CSDL COMPANY – SUPERVISION, a 1:N relationship type between EMPLOYEE (in the supervisor role) and EMPLOYEE (in the supervisee role) Both participations are determined to be partial, after the users indicate that not every employee is a supervisor and not every employee has a supervisor – WORKS_ON, determined to be an M:N relationship type with attribute Hours, after the users indicate that a project can have several employees working on it Both participations are determined to be total – DEPENDENTS_OF, a 1:N relationship type between EMPLOYEE and DEPENDENT, which is also the identifying relationship for the weak entity type DEPENDENT The participation of EMPLOYEE is partial, whereas that of DEPENDENT is total 42 Review Questions Define the following terms: entity, attribute, attribute value, relationship instance, composite attribute, multivalued attribute, derived attribute, complex attribute, key attribute, value set (domain) What is an entity type? What is an entity set? Explain the differences among an entity, an entity type, and an entity set Explain the difference between an attribute and a value set 43 Review Questions What is a relationship type? Explain the differences among a relationship instance, a relationship type, and a relationship set When is the concept of a weak entity used in data modeling? Define the terms owner entity type, weak entity type, identifying relationship type, and partial key Can an identifying relationship of a weak entity type be of a degree greater than two? Give examples to illustrate your answer 44 Exercises • Consider the following set of requirements for a university database that is used to keep track of students’ transcripts This is similar but not identical to the database 1.The university keeps track of each student’s name, student number, social security number, current address and phone, permanent address and phone, birthdate, sex, class, major department, minor department, and degree program (B.A., B.S., , Ph.D.) Some user applications need to refer to the city, state, and zip code of the student’s permanent address and to the student’s last name Both social security number and student number have unique values for each student 45 Exercises Each department is described by a name, department code, office number, office phone, and college Both name and code have unique values for each department Each course has a course name, description, course number, number of semester hours, level, and offering department The value of course number is unique for each course Each section has an instructor, semester, year, course, and section number The section number distinguishes sections of the same course that are taught during the same semester/year; its values are 1, 2, 3, , up to the number of sections taught during each semester A grade report has a student, section, letter grade, and numeric grade (0, 1, 2, 3, or 4) 46 ... One-to-Many Relationship: nhiều thể loại thực thể B kết hợp với thể loại thực thể A thể loại thực thể A kết hợp với thể loại thực thể B – Many-to-Many Relationship: Nhiều thể loại thực thể A kết. .. 3: Hiện thực sở liệu sử mơ hình sở liệu quan hệ mơ hình sở liệu hướng đối tượng – Bước gọi thiết kế logic ánh xạ mơ hình liệu – Kết bước lược đồ sở liệu thực sở liệu hệ quản trị sở liệu • Bước... đa số tối thiểu thể thực thể B kết hợp với thể thực thể A Có loại quan hệ hai loại thực thể A B – One-to-One Relationship: tối đa thể loại thực thể B kết hợp với thể loại thực thể B ngược lại

Ngày đăng: 20/05/2021, 01:53

Từ khóa liên quan

Mục lục

  • Slide 1

  • Giới thiệu

  • Các bước thiết kế một CSDL

  • Các bước thiết kế một CSDL

  • Các bước thiết kế một CSDL

  • Ví dụ CSDL Company

  • Ví dụ CSDL Company

  • Entity Types, Entity Sets, Attributes, keys

  • Entity Types, Entity Sets, Attributes, keys

  • Entity Types, Entity Sets, Attributes, keys

  • Entity Types, Entity Sets, Attributes, keys

  • Entity Types, Entity Sets, Attributes, keys

  • Entity Types, Entity Sets, Attributes, keys

  • Entity Types, Entity Sets, Attributes, keys

  • Entity Types, Entity Sets, Attributes, keys

  • Relationships, Relationship Types

  • Relationships, Relationship Types

  • Relationships, Relationship Types

  • Relationships, Relationship Types

  • Relationships, Relationship Types

Tài liệu cùng người dùng

Tài liệu liên quan