งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

Chapter 5 Database Design

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "Chapter 5 Database Design"— ใบสำเนางานนำเสนอ:

1 Chapter 5 Database Design
Part 2 Data Management

2 Agenda ER-Diagram 12 Integrity Rules

3 1. ER-Diagram

4 ER-Diagram ER-Diagram is a visual representation of data that describes how data is related to each other.

5 Symbols and Notations

6 Components of E-R Diagram
Entity Attribute Relationship

7 1. Entity An Entity can be any object, place, person or class. In E-R Diagram, an entity is represented using rectangles. Consider an example of an Organisation. Employee, Manager, Department, Product and many more can be taken as entities from an Organisation.

8 Weak Entity Weak entity is an entity that depends on another entity. Weak entity doen't have key attribute of their own. Double rectangle represents weak entity.

9 2. Attribute An Attribute describes a property or characterstic of an entity. For example, Name, Age, Address etc can be attributes of a Student. An attribute is represented using eclipse.

10 Key Attribute Key attribute represents the main characterstic of an Entity. It is used to represent Primary key. Ellipse with underlying lines represent Key Attribute.

11 Composite Attribute An attribute can also have their own attributes. These attributes are known as Composite attribute.

12 3. Relationship A Relationship describes relations between entities. Relationship is represented using diamonds. There are three types of relationship that exist between Entities. Binary Relationship (one to one, one to many, many to one, many to many) Recursive Relationship Ternary Relationship

13 Binary Relationship Binary Relationship means relation between two Entities. This is further divided into three types. 1. One to One : This type of relationship is rarely seen in real world. The above example describes that one student can enroll only for one course and a course will also have only one Student. This is not what you will usually see in relationship.

14 Binary Relationship 2. One to Many : It reflects business rule that one entity is associated with many number of same entity. The example for this relation might sound a little weird, but this menas that one student can enroll to many courses, but one course will have one Student. The arrows in the diagram describes that one student can enroll for only one course.

15 Binary Relationship 3. Many to One : It reflects business rule that many entities can be associated with just one entity. For example, Student enrolls for only one Course but a Course can have many Students.

16 Binary Relationship 4. Many to Many
The above diagram represents that many students can enroll for more than one courses.

17 Binary Relationships

18 Recursive Relationship
When an Entity is related with itself it is known as Recursive Relationship.

19 Ternary Relationship Relationship of degree three is called Ternary relationship.

20 Ternary Relationship

21 An Associative Entity

22 Ternary Relationship as an Associative Entity

23 Business Rules and Computer Science
Example 1:

24 Business Rules What are the cardinalities of all the relationship?
Example 2: What are the cardinalities of all the relationship? Each Student attends only one class at a time. Hence it is a 1: 1 relation. Each class has one or more sections. Hence it can be considered as 1: N relation. Each student attends many subjects and each class has many subjects. Hence it is a 1:N relation. Note: If you look at STUDENT and CLASS relationship as many Students attend one class, then it would be an M: 1 relation.

25 ER diagram for simple Student database
Example 2: ER diagram for simple Student database

26 Glossary Entity Attribute Relationship
Cardinality: The number of elements in a set or other grouping, as a property of that grouping.

27 2. 12 Integrity Rules Codd's 12 Rules

28 Rule 1: The Information The information rule simply requires all information in the database to be represented in one and only one way, Namely by values in column positions within rows of tables. กฎสารสนเทศ (The information rule) : สารสนเทศทั้งหมดในฐานข้อมูลต้องแสดงอยู่ ในรูปแบบเดียวเท่านั้น คือ Relation ซึ่งถือ ว่าเป็นหลักการพื้นฐานของแบบจำลองเชิง สัมพันธ์

29 Rule 2: Guaranteed Access
This rule is essentially a restatement of the fundamental requirement for primary keys. It says that every individual scalar value in the database must be logically addressable by specifying the mane of the containing table, the name of the containing column and the primary key value of the containing row. กฎการรับประกันการเข้าถึง (The quaranteed access rule) : ค่าทุกค่าที่ถูกจัดเก็บไว้ในฐานข้อมูล ต้องสามารถอ้างอิงได้ในทางตรรกะโดยการใช้ ชื่อตาราง ชื่อคอลัมน์ และค่าของคีย์หลัก

30 Rule 3: Systematic Treatment of Null Values
The DBMS is required to support a representation of "missing information and inapplicable information" that is systematic, distinct from all regular values (for example, "distinct from zero or any other number," in the case of numeric values), and independent of data type. It is also implied that such representations must be manipulated by the DBMS in a systematic way. การจัดการค่า Null อย่างเป็นระบบ (Systematic treatment of null values) ระบบจัดการฐานข้อมูลต้องมี การใช้ค่า Null แทน “สารสนเทศที่ขาดหายไป (missing information) หรือไม่มีค่าสารสนเทศที่เหมาะสม (in applicable information)” อย่างเป็นระบบ

31 Rule 4: Dynamic Online Catalog Based on the Relational Model
The system is required to support an online, inline, relational catalog that is accessible to authorized users by means of their regular query language. แอคทีพออนไลน์แคททาล๊อคที่อยู่บนพื้นฐาน ของแบบจำลองเชิงสัมพันธ์ (Active online catalog based on the relational model) ระบบต้อง สนับสนุนRelationแบบOnlineที่สามารถเข้าถึงได้ โดยผู้ใช้ที่มีสิทธิผ่านทางภาษาคิวรี

32 Rule 5: Comprehensive Data Sub-language
The system must support a least one relational language that (a) has a linear syntax, (b) can be used both interactively and within application programs, and (c) supports data definition operations (including view definitions), data manipulation operations (update as well as retrieval), security and integrity constraints, and transaction management operations (begin, commit, and rollback). กฎภาษาข้อมูล (The Comprehensive data sublanguage rule) ระบบต้องสนับสนุนภาษาที่เป็น Relation อย่างน้อย 1 ภาษา ที่สามารถใช้ได้ทั้งแบบโต้ตอบและผ่านทางโปรแกรม สนับสนุน การนิยามข้อมูลรวมทั้งการจัดการข้อมูล ความ มั่นคงและเงื่อนไข Integrity การจัดการ Transaction A relational system may support several languages and various modes of terminal use (for example, the fill-in-the-blanks mode). However, there must be at least one language whose statements are expressible, per some well-defined syntax, as character strings, that is comprehensive in supporting all of the following items: Data Definition View Definition Data manipulation (interactive and by program) Integrity Constraints Authorization Transaction boundaries (begin, commit, and rollback) ระบบ DBMS แบบรีเลชั่น ควร มีภาษาอย่างอย่างน้อย 1 ภาษา ที่สามารถกระทำการต่อไปนี้ได้ นิยามโครงสร้างระบบข้อมูล นิยามวิว เปลี่ยนแปลงแก้ไขข้อมูล ทั้งด้วยวิธีการใช้คำสั่งแบบ interactive และ ด้วยการเขียนโปรแกรม ควบคุม integrity ทั้ง integrity ของข้อมูล (entity integrity) ของการอ้างอิงด้วย (referential integrity) โดยขอให้ดูความหมายของ integrity ทั้ง 2 นี้ได้ในกฎข้อที่ 10 (integrity นักวิชาการบางท่านหมายถึง บูรณภาพ คือ ลักษณะที่มีความหมายมั่นคงเป็นปึกแผ่น) การใช้สิทธิการใช้งาน ขอบเขตของ transaction

33 Rule 6: View Updating All views that are theoretically updateable are also updateable by the system. กฎการแก้ไขวิว (The view update rule) วิวทุกวิว สามารถเปลี่ยนแปลงแก้ไขได้ทางทฤษฎีต้องสามารถ เปลี่ยนแปลงแก้ไขโดยระบบ ผู้ใช้แต่ละคน เห็นระบบข้อมูลในมุมมอง หรือ วิว ที่แตกต่างกัน ระบบฐานข้อมูลต้อง สามารถ เปลี่ยนแปลงแก้ไขข้อมูล ตาม มุมมอง หรือ วิวที่ แต่ต่างกันได้ ระบบฐานข้อมูล ( DBMS ) จะต้อง สามารถ ตัดสินได้ว่าผู้ใช้สามารถเพิ่มเติมทัพเพิล (tuple หมายถึง แถว หรือ เรคอร์ดใน ตาราง)ลบทัพเพิล หรือแก้ไขข้อมูลในคอลัมน์ใด ๆ โดยกระทำผ่านวิวได้หรือไม่

34 Rule 7: High-Level Insert, Update, and Delete
The system must support set-at-a-time INSERT, UPDATE, and DELETE operators. The capability of handling a base relation or a derived relation as a single operand applies not only to the retrieval of data but also to the insertion, update, and deletion of data. การแทรก แก้ไข และลบในระดับสูง (High-level insert, update and delete) ระบบต้องสนับสนุนการแทรก แก้ไข และลบข้อมูลในลักษณะของเซต ระบบฐานข้อมูล ( DBMS ) ควรจะมีภาษาที่สามารถให้ผู้ใช้ เพิ่ม ลด หรือแก้ไข ข้อมูลในหลาย ๆ แถว หรือ หลาย ๆ คอลัมน์ ได้ด้วยการออกคำสั่ง เพียงคำสั่ง เดียว ซึ่งในปัจจุบัน ส่วนใหญ่ระบบฐานข้อมูล (DBMS) จะมีภาษาที่ชื่อ SQL เป็นมาตรฐาน

35 Rule 8: Physical Data Independence
Self-explanatory. Application programs and terminal activities remain logically unimpaired whenever any changes are made in either storage representations or access methods. ความเป็นอิสระของข้อมูลเชิงกายภาพ (Physical data independence) การเปลี่ยนแปลงใด ๆ ในระดับ Schema ทางกายภาพจะไม่มีผลกระทบต่อ Schema ทางตรรกะ ผู้ใช้งาน ระบบฐานข้อมูล ( DBMS ) ไม่จำเป็นจะต้องรับรู้ เกี่ยวกับการจัดเก็บข้อมูลจริง รวมทั้งการเปลี่ยนแปลง วิธีการจัดเก็บเหล่านี้ และการเข้าถึงข้อมูล ด้วยการระบุ ค่าเช่นเดิมนี้ก็จะได้คำตอบเหมือนเดิมเสมอ ไม่ว่าระบบจะ ได้มีการเปลี่ยนแปลง ทางด้านกายภาพอย่างไร

36 Rule 9: Logical Data Independence
Self-explanatory. Application programs and terminal activities remain logically unimpaired when information-preserving changes of any kind that theoretically permit unimpairment are made to the base tables. ความเป็นอิสระของข้อมูลเชิงตรรกะ (Logical data independence) การเปลี่ยนแปลงใด ๆ ใน Schema ทางตรรกะจะไม่มีผลกระทบต่อโปรแกรม ประยุกต์

37 Rule 10: Integrity Independence
Integrity constraints must be specified separately from application programs and stored in the catalog. It must be possible to change such constraints as and when appropriate without unnecessarily affecting existing applications. Integrity constraints specific to a particular relational database must be definable in the relational data sub-language and storable in the catalog, not in the application programs. ความเป็นอิสระของอินทิกริตี (Integrity independence) เงื่อนไขของ Integrity ต้องมีการกำหนดแยกต่างหากจาก โปรแกรมประยุกต์ และจัดเก็บไว้ในแคททาล็อค ทั้งนี้ทำ ให้เกิดความเป็นไปได้ในการที่จะเปลี่ยนแปลงเงื่อนไขของ Integrity โดยไม่มีผลกระทบต่อโปรแกรมประยุกต์ที่มีอยู่

38 Rule 11: Distribution Independence
Existing applications should continue to operate successfully (a) when a distributed version of the DBMS is first introduced; (b) when existing distributed data is redistributed around the system. A relational DBMS has distribution dependence. ความเป็นอิสระของการกระจาย (Distribution independence) โปรแกรมที่มีอยู่แล้วสามารถทำงาน ต่อไปได้ เมื่อ Version การกระจายเริ่มถูกทำมาใช้ ผู้ใช้ระบบไม่ต้องให้ความสนใจว่า ข้อมูลจะถูก จัดเก็บอย่างไร แม้แต่จะถูกโยกย้าย ไปยังเครื่อง คอมพิวเตอร์ เครื่องอื่นที่เชื่อมโยงไว้ก็ตาม

39 Rule 12: Nonsubversion If the system provides a low-level (record-at-a-time) interface, then that interface cannot be used to subvert the system (e.g.) bypassing a relational security or integrity constraint. If a relational system has a low-level (single record at a time) language, that low level cannot be used to subvert or bypass the integrity rules and constraints expressed in the higher-level relational language (multiple records at a time). กฎการไม่มีเวอร์ชันย่อย (The nonsubversion rule) ถ้าระบบอนุญาต ให้มีการติดต่อได้ในระดับต่ำสุด คือ ครั้งละ Record และการ ติดต่อนี้ต้องไม่ถูกใช้เพื่อเป็นทางลัดโดยไม่ผ่านระบบความมั่นคง หรือเงื่อนไข Integrity กฎเกณฑ์ต่าง ๆ โดยเฉพาะกฎเกี่ยวกับ integrity จะต้อง สามารถใช้ควบคุมความ ถูกต้องของข้อมูลในระบบได้ ตลอดเวลา ไม่ว่าผู้ใช้จะเข้าถึงข้อมูลด้วยเครื่องมือใด ๆ (เช่น) ระบบ 4th GL หรือ 3nd GL) ก็ตาม

40 Summary คีย์หลักของรีเลชั่น จะต้องมีค่าข้อมูลที่ไม่ซ้ำ กัน (unique)  เนื่องจากคุณสมบัติของคีย์หลัก จะ เป็นแอททริบิวท์ที่ใช้ในการเจาะจงแถวข้อมูลใด แถวข้อมูลหนึ่งในรีเลชัน ดังนั้นจึงจะให้ค่า ข้อมูลที่ซ้ำกันไม่ได้ ค่าข้อมูลของคีย์หลักจะต้องไม่เป็นค่าว่าง (Null Value)จะต้องไม่มีแอททริบิวท์ใดที่เป็น ส่วนประกอบของคีย์หลักของรีเลชันนั้นเป็นค่า ว่าง เพราะค่าของข้อมูลในคีย์หลักจะถูกใช้ เจาะจงถึงข้อมูลแถวใด ๆ ในรีเลชัน 

41 Summary กฎความบูรณภาพของเอนทิตี้ (Entity Integrity Rule)กฎความบูรณภาพของเอนทิตี้ เป็นกฎที่ ใช้กำหนดเพื่อให้ข้อมูลของเอนทิตี้ มี ความถูกต้อง ซึ่งกล่าวไว้ว่า "แอตทริบิวส์ที่ ทำหน้าที่เป็นคีย์หลักของรีเลชัน ไม่สามารถ มีค่าเป็นค่าว่างได้ (Null Value)" และจะต้องมี คุณสมบัติที่เป็นเอกลักษณ์ (Identity) คือ สามารถระบุข้อมูลแอตทริบิวส์อื่นๆ ที่อยู่ในทู เพิลเดียวกันได้

42 กฎความบูรณภาพของการอ้างอิง (Referential Integrity Rule)
กฎความบูรณภาพของการอ้างอิง คือกฎที่ใช้รักษา ความถูกต้องของข้อมูลที่มีความสัมพันธ์กันของเอนทิตี้ ซึ่งได้กล่าวไว้ว่า "ค่าของคีย์นอกในรีเลชัน จะต้อง มีข้อมูลอยู่ในอีก รีเลชันหนึ่ง ที่คีย์นอกของรีเลชัน นั้นอ้างอิงถึง"ในบางกรณีคีย์นอกอาจเป็นค่าว่างได้ ถ้านโยบายขององค์กร อนุญาตให้ค่าคีย์นอกเป็น ค่าว่างได้ กรณีหากมีการลบ หรือแก้ไขข้อมูล ใน รีเลชันที่ถูกอ้างอิงถึง ซึ่งจะทำให้สูญเสียความบูรณ ภาพของข้อมูล ดังตัวอย่างรูปที่ 3.6 หากมีการแก้ไข หรือลบข้อมูลของรีเลชัน Major ในแอตทริบิวส์ Major ซึ่งมีความสัมพันธ์อยู่กับรีเลชัน Student จะทำ ให้ความสัมพันธ์ของข้อมูลเสียหาย ดังนั้นจึงต้อง เลือก การกระทำเพื่อไม่ให้ความสัมพันธ์ของข้อมูล สูญเสียไปดังนี้

43 กรณีการแก้ไขข้อมูล 1. ห้ามทำการแก้ไขข้อมูลในรีเลชันที่ถูกอ้างถึง นั้น เนื่องจากจะทำให้ข้อมูลในรีเลชันที่ อ้างอิงมา ไม่สามารถอ้างอิงข้อมูลได้ 2. อนุญาตให้ทำการแก้ไขข้อมูลในรีเลชันที่ถูก อ้างอิงถึงได้ แต่จะต้องตามไปแก้ไขข้อมูล ในรีเลชันที่อ้างอิงมาให้ตรงกับข้อมูลที่แก้ไข ใหม่ทั้งหมด 3. อนุญาตให้ทำการแก้ไขข้อมูลในรีเลชันที่ถูก อ้างอิงถึงได้ โดยการแก้ไขข้อมูลในรีเลชัน ที่อ้างอิงมาให้มีค่าเป็น ค่าว่าง

44 กรณีการลบข้อมูล 1. ห้ามทำการลบข้อมูลในรีเลชันที่ถูกอ้างถึง นั้น เนื่องจากจะทำให้ข้อมูลใน รีเลชันที่ อ้างอิงมา ไม่สามารถอ้างอิงข้อมูลได้ 2. อนุญาตให้ทำการลบข้อมูลในรีเลชันที่ถูก อ้างอิงถึงได้ แต่จะต้อง ตามไปลบข้อมูลใน รีเลชัน ที่อ้างอิงมาทั้งหมด 3. อนุญาตให้ทำการลบข้อมูลในรีเลชันที่ถูก อ้างอิงถึงได้ โดยการแก้ไขข้อมูลในรีเลชัน ที่อ้างอิงมาให้มีค่าเป็น ค่าว่าง (Null value)

45 References This is C.J Date's version of the 12 Rules from AN INTRODUCTION TO DATABASE SYSTEMS (5th edition) as set forth in pages Oracle Codd's 12 Rules ER-Diagram diagram.php


ดาวน์โหลด ppt Chapter 5 Database Design

งานนำเสนอที่คล้ายกัน


Ads by Google