SlideShare a Scribd company logo
การสร้ างแบบจาลองข้ อมูล และการวิเคราะห์ ข้อมูล
                       (Data Modeling and Analysis)
                                  *****
                        Key Definitions นิยามหลัก

1. Data model แบบจาลองข้ อมูล
        A formal way of representing the data that are used and created
        by a business system
           เป็ นวิธีที่แทนข้อมูลที่ถกใช้และสร้างขึ้นจากระบบ
                                    ู
        Shows the people, places and things about which data is
        captured and the relationships among them.
          แสดงถึง บุคคล สถานที่ และสิ่ งของ ที่จะเก็บข้อมูลและความสัมพันธ์
        ระหว่างสิ่งที่กล่าวถึงเหล่านี้
 2. Logical data model แบบจาลองข้ อมูลเชิงตรรก
        Shows the organization of data without indicating how it is
        stored, created, or manipulated.
            แสดงให้เห็นรายการข้อมูลโดยไม่ได้คานึงถึงว่าจะเก็บ สร้าง หรื อจัดการ
        กับมันอย่างไร

3. Physical data model แบบจาลองข้ อมูลเชิงกายภาพ
        Shows how the data will actually be stored in databases or files.
           แสดงให้เห็นว่าข้อมูลถูกเก็บจริ ง ๆ ไว้ในฐานข้อมูล หรื อ ไฟล์ อย่างไร
                                      -----------
       THE ENTITY-RELATIONSHIP DIAGRAM (ERD)
                  แผนภาพแสดงความสัมพันธ์ของ Entity
                                ***
What Is an ERD? ERD คืออะไร
    A picture showing the information created, stored, and used by a
    business system.
           ภาพที่แสดงข้อมูลที่สร้างขึ้น จัดเก็บ และถูกใช้ในระบบ
     Lines drawn between entities show relationships among the data
          เส้นที่ลากเชื่อมระหว่าง Entity แสดงความสัมพันธ์ระหว่างข้อมูล
                                       5-1
An ERD Example   ตัวอย่ างของ ERD




                                5-2
ERD Elements      องค์ประกอบของ ERD




Entity

     A person, place, event, or thing about which data is collected
           บุคคล สถานที่ เหตุการณ์ หรื อ สิ่ งของที่เราจะทาการรวบรวมข้อมูล
     Must be multiple occurrences to be an entity
          สิ่ งที่จะเป็ น Entity ต้องมี Instance มากกว่า 1 Instance
          Example: If a firm has only one warehouse, the warehouse is
          not an entity.
                    ตัวอย่างเช่น ถ้าบริ ษทหนึ่งมี คลังสิ นค้า (warehouse) เพียงแห่ง
                                         ั
           เดียว warehouse ก็ไม่เป็ น Entity
           However, if the firm has several warehouses, the warehouse
           could be an entity if the firm wants to store data about each
           warehouse instance.
                                       5-3
อย่างไรก็ตาม ถ้าบริ ษทที่หลาย warehouse แล้ว warehouse ก็
                                      ั
           สามารถเป็ น Entity ได้ ถ้าบริ ษทต้องการเก็บข้อมูลเกี่ยวกับค่าจริ ง
                                          ั
           (Instance) แต่ละค่าของ warehouse

Entities and Instances




Attributes (Element, Property, Field)
     Information captured about an entity
          รายละเอียดเกี่ยวกับ Entity
     Only those used by the organization should be included in the
     model
           เฉพาะที่องค์กรต้องการใช้เท่านั้นที่จะใส่ไว้ในแบบจาลอง
     Attribute names are nouns
           ชื่อของ Attribute ต้องเป็ นคานาม
     Sometimes entity name is added at the beginning of the attribute
     name for clarity
                  ็
           บางทีกใส่ชื่อ Entity ไว้ขางหน้าชื่อ Attribute เพื่อให้ทาให้เห็นชัดเจน
                                     ้
     เช่น subject_name, student_name, customer_add
                                       5-4
Relationships ความสั มพันธ์
     Associations between entities
           เป็ นความสัมพันธ์ระหว่าง Entity
     The first entity in the relationship is the parent entity; the second
     entity in the relationship is the child entity
           Entity แรกในความสัมพันธ์เรี ยกว่า Parent Entity (Entity พ่อแม่)
     และ Entity ที่สองเรี ยกว่า Child Entity (Entity ลูก)
     Relationships should have active verb names
           ชื่อความสัมพันธ์ควรเป็ นคากริ ยา
     Relationships go in both directions
           ความสัมพันธ์จะเป็ นแบบสองทิศทาง
Cardinality
    Cardinality
          Refers to the number of times instances in one entity can be
          related to instances in another entity
                หมายถึง จานวนของ Instance ของ Entity หนึ่งที่สามารถจะ
                       ั
              สัมพันธ์กบ Instance ของอีก Entity หนึ่งได้
                 One instance in an entity refers to one and only one
                 instance in the related entity (1:1)
                                                                     ั
                       ถ้า Instance หนึ่ง ของ Entity หนึ่งไปสัมพันธ์กบ
                 Instance ของอีก Entity หนึ่ งเพียงตัวเดียวเท่านั้น เรี ยกว่า
                 มีความสัมพันธ์แบบ 1 ต่อ 1 (One-to-one relationship) เขียน
                 แทนด้วยสัญลักษณ์ 1:1


                                   1                            1




                 One instance in an entity refers to one or more
                 instances in the related entity (1:N)

                                       5-5
ั
       ถ้า Instance หนึ่ง ของ Entity หนึ่งไปสัมพันธ์กบ หนึ่ง
หรื อมากกว่าหนึ่ง Instance ของอีก Entity หนึ่ง เรี ยกว่า
มีความสัมพันธ์แบบ 1 ต่อ N (One-to-many relationship)
เขียนแทนด้วยสัญลักษณ์ 1:N


               1                               N
Customer                    bought                 Product




One or more instances in an entity refer to one or more
instances in the related entity (M:N)
      ถ้า Instance หนึ่ง หรื อมากกว่า หนึ่ง ของ Entity หนึ่งไป
            ั
สัมพันธ์กบ หนึ่งหรื อมากกว่าหนึ่ง Instance ของอีก Entity หนึ่ง
เรี ยกว่า มีความสัมพันธ์แบบ M ต่อ N (Many-to-many
relationship) เขียนแทนด้วยสัญลักษณ์ M:N


                M         Reserves         N
Passenger                                           Flight
                           Seat On




                    5-6
สัญลักษณ์ที่ใช้ แทน Cardinality ของ Relation

   Cardinality        Minimum       Minimum     Graphic
  Interpretation      Instances     Instances   Notation

   Exactly one            1                 1


   Zero or one            0                 1

   One or more            1        Many (>1)


  Zero or more            0        Many (>1)


 More than one            >1            >1




                                      5-7
ตัวอย่างของการเขียน ERD อีกแบบหนึ่ง




BUILDING AN ENTITY-RELATIONSHIP DIAGRAM (ERD)
(การสร้ าง ERD)
Steps in Building ERDs ขั้นตอนในการสร้าง ERD
     Identify the entities
           กาหนด Entity
     Add attributes
           เพิ่ม Attribute
     Identify relationships
          กาหนดความสัมพันธ์
                                   5-8
Identify the Entities
     Identify major categories of information
             กาหนดกลุ่มของสารสนเทศที่สาคัญ
             If available, check the DFD for data stores, external entities,
             and data flows
                   ถ้าเป็ นไปได้ ตรวจสอบกับ DFD เพื่อดู Data Store, External
            Entity และ Data Flow
      Verify that there is more than one instance of the entity that occurs
      in the system
           ตรวจสอบ Entity ให้แน่ใจว่ามีค่า Instance เกิดขึ้นในระบบมากกว่า 1 ค่า
Add Attributes
    Identify attributes of the entity that are relevant to the system
    under development
          กาหนด Attribute ของ Entity ที่สอดคล้องกับระบบที่กาลังพัฒนา
          Check the DFD for details on data flows and data stores
                ตรวจสอบ DFD เพื่อดูรายละเอียดเกี่ยวกับ Data Store และ
             Data Flow เพื่อดูความสอดคล้องกัน
             Check the data requirements of the user requirements
                    ตรวจสอบความต้องการด้านข้อมูล ตามที่ระบุไว้ในความต้องการ
             ของผูใช้
                  ้
             Interview knowledgeable users
                   สัมภาษณ์ผใช้ที่มีความรู้เกี่ยวกับเรื่ องนั้น ๆ
                            ู้

             Perform document analysis on existing forms and reports
                   วิเคราะห์เอกสารที่มีอยู่ เช่น แบบฟอร์ม และรายงาน
Identify Relationships
     Start with an entity and identify all entities with which it shares
     relationships
           เริ่ มด้วยการระบุ Entity ขึ้นมา Entity หนี่งแล้วหา Entity ทั้งหมดที่มี
                      ั
         ความสัมพันธ์กบมัน
      Describe the relationship with the appropriate verb phrase
             กาหนดความสัมพันธ์ดวยวลีที่มีคากริ ยาที่เหมาะสม
                               ้
                                           5-9
Determine the cardinality by discussing the business rules with
     knowledgeable users
          พิจารณา Cardinality ตามกฎเกณฑ์ ร่ วมกับผูใช้ที่มีความรู้ในเรื่ องที่
                                                   ้
     เกี่ยวข้อง
ERD Building Tips (กลเม็ดในการสร้ าง ERD)
    Data stores of the DFD should correspond to entities
         Data stores ของ DFD ควรจะสอดคล้องกับ Entity ต่าง ๆ
    Only include entities with more than one instance of information
         คง Entity ที่มีค่าของ Instance มากกว่า 1 ค่า ไว้ เท่านั้น




                                      5-10
VALIDATING AN ERD
                 (การตรวจสอบความถูกต้องของ ERD)
                              *****
Design Modeling Guidelines Summary (สรุ ปหลักการในการสร้างแบบจาลอง)




     สรุปแนวทางในการเขียน ERD
           1. Entity ประเทศ ที่มีชื่อเพียง 1 Instance (เช่น เม็กซิ โก) Entity นี้ ก็
              ไม่จาเป็ นต้องมี
                            ่
           2. ถ้าเรี ยกครู วา Professor แล้วใน ERD ก็ควรจะมี Entity ที่ชื่อ
              Professor เพื่อให้มีความคงเส้นคงวา
           3. ทาไมต้องเก็บข้อมูลเกี่ยวกับมหาวิทยาลัยทั้งหมด? จาเป็ นต้องเก็บชื่อ
              คนก่อตั้ง และอธิการบดีคนแรกของแต่ละมหาวิทยาลัยด้วยหรื อ? ถ้าไม่
                                         ็
              จาเป็ น Attribute เหล่านี้กควรจะเอาทิ้งไปจาก ERD


                                       5-11
4.   ชื่อ Attribute ใน Entity ที่ชื่อ Subject มีการเขียนที่ไม่ดี เช่น
     name เพราะว่าถ้าใครเห็นเดี่ยว ๆ จะไม่มีทางทราบเลยว่ามันอยูใน   ่
     Entity ใด จะเป็ นการดี ถ้าเริ่ มต้นแต่ละ Attribute ด้วยคาว่า SUB
     ตัวอย่าง name ก็แก้เป็ น SUB_name จะสื่ อดีกว่า และ area ก็
     เช่นเดียวกัน ถ้าแทนด้วย department หรื อ สาขาของการวิจย ก็จะ ั
     สื่ อได้ดีกว่าเช่นเดียวกัน
5.   Attribute ที่ชื่อ name ควรจะแยกเป็ น Last_name กับ
     First_name มิเช่นนั้น อาจเกิดปั ญหาในการจัดการข้อมูลภายหลัง
                                              ่
     เช่น ไม่สามารถเรี ยงนามสกุลได้ ถ้ามันอยูรวมกับชื่อ
6.   Model นี้ แสดงให้เห็นว่า ครู แต่ละคนสามารถทางานได้ 1
     มหาวิทยาลัยเท่านั้น แล้วครู ที่ตองสอนหลายมหาวิทยาลัยจะทาอย่างไร
                                     ้
     ควรจะต้องมีการบอกเงื่อนไขไว้ใน Model หรื อ ในเอกสารเพื่อให้
     เกิดความชัดเจนว่ามีขอตกลงอย่างไร
                             ้
                            --------------




                          5-12
YOUR TURN

1. การวิเคราะห์ และสร้ าง ERD จากแบบฟอร์ ม

                                  Welsh Clothing
                                   Order form
Order Number: AB1242                    Customer Number: C5432
Order Date: 22/2/2003                   Customer Name: Dai the Death
                                        Customer Address: 123 Rama VRoad,
                                                          Dusit, Bkk. 11300

Item number       Description       Quantity      Price (Baht)   Cost (Baht)
      234         Green socks            4            20.00         80.00
      532         Yellow hats            5            30.00         150.00
      653         Purple shirts          3            200.00        600.00
                                                      Cost of Order: 830.00
                                                               Vat: 58.10
                                                        Total Cost: 888.10




      จากใบสังสิ นค้าที่กาหนดให้ จงทาสิ่ งต่อไปนี้ (สร้าง ERD)
             ่
           1. วิเคราะห์หา Entity
           2. หา Attribute
           3. สร้างความสัมพันธ์ระหว่าง Entity
           4. กาหนด Cardinality




                                       5-13
2. การวิเคราะห์ และสร้ าง ERD จากรายงาน

                          Handy Tool Ltd.
                      Monthly Salesperson Report

Salesperson number: 1001                       Date: May 2006
Salesperson name: Somsak Pakdee
Sales area: West

Customer          Customer      Warehouse      Warehouse         Sales
 number            name          code           location
  101           Smith & Co.         2             Bilston     12,950.00
  102           Jones & Son         4             Oxley       21,255.00
  103           Smithsons           7             Parklane    10,199.80
                                           Total monthly sales 44,404.80

      จากรายงานยอดขายประจาเดือนของพนักงานขาย จงทาสิ่งต่อไปนี้ (สร้าง ERD)
           1. วิเคราะห์หา Entity
           2. หา Attribute
           3. สร้างความสัมพันธ์ระหว่าง Entity
           4. กาหนด Cardinality




                                    5-14

More Related Content

Similar to แบบจำลองข้อมูล

ฐานข้อมูลนะสอน
ฐานข้อมูลนะสอนฐานข้อมูลนะสอน
ฐานข้อมูลนะสอนsariya25
 
Entity Relationship
Entity RelationshipEntity Relationship
การจัดการฐานข้อมูล
การจัดการฐานข้อมูลการจัดการฐานข้อมูล
การจัดการฐานข้อมูล
Orapan Chamnan
 
Lesson 1 intro2_db
Lesson 1 intro2_dbLesson 1 intro2_db
Lesson 1 intro2_db
Oracle in RRU
 
Lesson 1 intro2_db
Lesson 1 intro2_dbLesson 1 intro2_db
Lesson 1 intro2_db
Oracle in RRU
 
ระบบฐานข้อมูลNew
ระบบฐานข้อมูลNewระบบฐานข้อมูลNew
ระบบฐานข้อมูลNewQoo Kratai
 
SlideShare เรื่อง การออกแบบฐานข้อมูล
SlideShare เรื่อง การออกแบบฐานข้อมูลSlideShare เรื่อง การออกแบบฐานข้อมูล
SlideShare เรื่อง การออกแบบฐานข้อมูล
Nithiwan Rungrangsri
 
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูลความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูลสุจิตรา แสงเรือง
 
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูลความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูลสุจิตรา แสงเรือง
 
Unit 3 er model
Unit 3 er modelUnit 3 er model
Unit 3 er model
jirawan_Malasai
 
ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018
 ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018 ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018
ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018
maruay songtanin
 

Similar to แบบจำลองข้อมูล (11)

ฐานข้อมูลนะสอน
ฐานข้อมูลนะสอนฐานข้อมูลนะสอน
ฐานข้อมูลนะสอน
 
Entity Relationship
Entity RelationshipEntity Relationship
Entity Relationship
 
การจัดการฐานข้อมูล
การจัดการฐานข้อมูลการจัดการฐานข้อมูล
การจัดการฐานข้อมูล
 
Lesson 1 intro2_db
Lesson 1 intro2_dbLesson 1 intro2_db
Lesson 1 intro2_db
 
Lesson 1 intro2_db
Lesson 1 intro2_dbLesson 1 intro2_db
Lesson 1 intro2_db
 
ระบบฐานข้อมูลNew
ระบบฐานข้อมูลNewระบบฐานข้อมูลNew
ระบบฐานข้อมูลNew
 
SlideShare เรื่อง การออกแบบฐานข้อมูล
SlideShare เรื่อง การออกแบบฐานข้อมูลSlideShare เรื่อง การออกแบบฐานข้อมูล
SlideShare เรื่อง การออกแบบฐานข้อมูล
 
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูลความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
 
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูลความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
ความรู้ทั่วไปเกี่ยวกับระบบฐานข้อมูล
 
Unit 3 er model
Unit 3 er modelUnit 3 er model
Unit 3 er model
 
ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018
 ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018 ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018
ออเจ้าถาม Baldrige ตอบ FAQs of Baldrige criteria 2018
 

More from skiats

การ Setup disk quota กับ user ทุกคน
การ Setup disk quota กับ user ทุกคนการ Setup disk quota กับ user ทุกคน
การ Setup disk quota กับ user ทุกคนskiats
 
อัลกอริทึมและการวิเคราะห์ปัญหา
อัลกอริทึมและการวิเคราะห์ปัญหาอัลกอริทึมและการวิเคราะห์ปัญหา
อัลกอริทึมและการวิเคราะห์ปัญหาskiats
 
รูปแบบโครงการ
รูปแบบโครงการรูปแบบโครงการ
รูปแบบโครงการskiats
 
ตัวแปรและค่าคงที่ basic data type
ตัวแปรและค่าคงที่ basic data typeตัวแปรและค่าคงที่ basic data type
ตัวแปรและค่าคงที่ basic data typeskiats
 
4 - statement
4  - statement4  - statement
4 - statementskiats
 
การใช้งาน phpMyadmin
การใช้งาน phpMyadminการใช้งาน phpMyadmin
การใช้งาน phpMyadminskiats
 
สถาปัตยกรรมฐานข้อมูล
สถาปัตยกรรมฐานข้อมูลสถาปัตยกรรมฐานข้อมูล
สถาปัตยกรรมฐานข้อมูลskiats
 
การรวบรวมความต้องการ
การรวบรวมความต้องการการรวบรวมความต้องการ
การรวบรวมความต้องการskiats
 
การกำหนดปัญหาและศึกษาความเป็นไปได้
การกำหนดปัญหาและศึกษาความเป็นไปได้การกำหนดปัญหาและศึกษาความเป็นไปได้
การกำหนดปัญหาและศึกษาความเป็นไปได้skiats
 
รวบรวมความต้องการ
รวบรวมความต้องการรวบรวมความต้องการ
รวบรวมความต้องการskiats
 
DFD ภาษาอังกฤษ
DFD ภาษาอังกฤษDFD ภาษาอังกฤษ
DFD ภาษาอังกฤษ
skiats
 
การเขียนแผนภาพ DFD
การเขียนแผนภาพ DFDการเขียนแผนภาพ DFD
การเขียนแผนภาพ DFDskiats
 
วงจรพัฒนาระบบ SDLC
วงจรพัฒนาระบบ SDLCวงจรพัฒนาระบบ SDLC
วงจรพัฒนาระบบ SDLCskiats
 
ความหมายการวิเคราะห์ระบบ
ความหมายการวิเคราะห์ระบบความหมายการวิเคราะห์ระบบ
ความหมายการวิเคราะห์ระบบskiats
 
อุปกรณ์รับและแสดงผล
อุปกรณ์รับและแสดงผลอุปกรณ์รับและแสดงผล
อุปกรณ์รับและแสดงผลskiats
 
ฐานข้อมูลเชิงสัมพันธ์
ฐานข้อมูลเชิงสัมพันธ์ฐานข้อมูลเชิงสัมพันธ์
ฐานข้อมูลเชิงสัมพันธ์skiats
 
การ Normalization
การ Normalizationการ Normalization
การ Normalizationskiats
 
Lecture1 การประมวลผลข้อมูล และฐานข้อมูล
Lecture1 การประมวลผลข้อมูล และฐานข้อมูลLecture1 การประมวลผลข้อมูล และฐานข้อมูล
Lecture1 การประมวลผลข้อมูล และฐานข้อมูลskiats
 
Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์
Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์
Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์skiats
 
Lecture5 ฐานข้อมูลเชิงสัมพันธ์
Lecture5 ฐานข้อมูลเชิงสัมพันธ์Lecture5 ฐานข้อมูลเชิงสัมพันธ์
Lecture5 ฐานข้อมูลเชิงสัมพันธ์skiats
 

More from skiats (20)

การ Setup disk quota กับ user ทุกคน
การ Setup disk quota กับ user ทุกคนการ Setup disk quota กับ user ทุกคน
การ Setup disk quota กับ user ทุกคน
 
อัลกอริทึมและการวิเคราะห์ปัญหา
อัลกอริทึมและการวิเคราะห์ปัญหาอัลกอริทึมและการวิเคราะห์ปัญหา
อัลกอริทึมและการวิเคราะห์ปัญหา
 
รูปแบบโครงการ
รูปแบบโครงการรูปแบบโครงการ
รูปแบบโครงการ
 
ตัวแปรและค่าคงที่ basic data type
ตัวแปรและค่าคงที่ basic data typeตัวแปรและค่าคงที่ basic data type
ตัวแปรและค่าคงที่ basic data type
 
4 - statement
4  - statement4  - statement
4 - statement
 
การใช้งาน phpMyadmin
การใช้งาน phpMyadminการใช้งาน phpMyadmin
การใช้งาน phpMyadmin
 
สถาปัตยกรรมฐานข้อมูล
สถาปัตยกรรมฐานข้อมูลสถาปัตยกรรมฐานข้อมูล
สถาปัตยกรรมฐานข้อมูล
 
การรวบรวมความต้องการ
การรวบรวมความต้องการการรวบรวมความต้องการ
การรวบรวมความต้องการ
 
การกำหนดปัญหาและศึกษาความเป็นไปได้
การกำหนดปัญหาและศึกษาความเป็นไปได้การกำหนดปัญหาและศึกษาความเป็นไปได้
การกำหนดปัญหาและศึกษาความเป็นไปได้
 
รวบรวมความต้องการ
รวบรวมความต้องการรวบรวมความต้องการ
รวบรวมความต้องการ
 
DFD ภาษาอังกฤษ
DFD ภาษาอังกฤษDFD ภาษาอังกฤษ
DFD ภาษาอังกฤษ
 
การเขียนแผนภาพ DFD
การเขียนแผนภาพ DFDการเขียนแผนภาพ DFD
การเขียนแผนภาพ DFD
 
วงจรพัฒนาระบบ SDLC
วงจรพัฒนาระบบ SDLCวงจรพัฒนาระบบ SDLC
วงจรพัฒนาระบบ SDLC
 
ความหมายการวิเคราะห์ระบบ
ความหมายการวิเคราะห์ระบบความหมายการวิเคราะห์ระบบ
ความหมายการวิเคราะห์ระบบ
 
อุปกรณ์รับและแสดงผล
อุปกรณ์รับและแสดงผลอุปกรณ์รับและแสดงผล
อุปกรณ์รับและแสดงผล
 
ฐานข้อมูลเชิงสัมพันธ์
ฐานข้อมูลเชิงสัมพันธ์ฐานข้อมูลเชิงสัมพันธ์
ฐานข้อมูลเชิงสัมพันธ์
 
การ Normalization
การ Normalizationการ Normalization
การ Normalization
 
Lecture1 การประมวลผลข้อมูล และฐานข้อมูล
Lecture1 การประมวลผลข้อมูล และฐานข้อมูลLecture1 การประมวลผลข้อมูล และฐานข้อมูล
Lecture1 การประมวลผลข้อมูล และฐานข้อมูล
 
Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์
Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์
Lecture7 การแปลงโมเดลแบบ E-R เป็นรูปแบบโมเดลเชิงสัมพันธ์
 
Lecture5 ฐานข้อมูลเชิงสัมพันธ์
Lecture5 ฐานข้อมูลเชิงสัมพันธ์Lecture5 ฐานข้อมูลเชิงสัมพันธ์
Lecture5 ฐานข้อมูลเชิงสัมพันธ์
 

แบบจำลองข้อมูล

  • 1. การสร้ างแบบจาลองข้ อมูล และการวิเคราะห์ ข้อมูล (Data Modeling and Analysis) ***** Key Definitions นิยามหลัก 1. Data model แบบจาลองข้ อมูล A formal way of representing the data that are used and created by a business system เป็ นวิธีที่แทนข้อมูลที่ถกใช้และสร้างขึ้นจากระบบ ู Shows the people, places and things about which data is captured and the relationships among them. แสดงถึง บุคคล สถานที่ และสิ่ งของ ที่จะเก็บข้อมูลและความสัมพันธ์ ระหว่างสิ่งที่กล่าวถึงเหล่านี้ 2. Logical data model แบบจาลองข้ อมูลเชิงตรรก Shows the organization of data without indicating how it is stored, created, or manipulated. แสดงให้เห็นรายการข้อมูลโดยไม่ได้คานึงถึงว่าจะเก็บ สร้าง หรื อจัดการ กับมันอย่างไร 3. Physical data model แบบจาลองข้ อมูลเชิงกายภาพ Shows how the data will actually be stored in databases or files. แสดงให้เห็นว่าข้อมูลถูกเก็บจริ ง ๆ ไว้ในฐานข้อมูล หรื อ ไฟล์ อย่างไร ----------- THE ENTITY-RELATIONSHIP DIAGRAM (ERD) แผนภาพแสดงความสัมพันธ์ของ Entity *** What Is an ERD? ERD คืออะไร A picture showing the information created, stored, and used by a business system. ภาพที่แสดงข้อมูลที่สร้างขึ้น จัดเก็บ และถูกใช้ในระบบ Lines drawn between entities show relationships among the data เส้นที่ลากเชื่อมระหว่าง Entity แสดงความสัมพันธ์ระหว่างข้อมูล 5-1
  • 2. An ERD Example ตัวอย่ างของ ERD 5-2
  • 3. ERD Elements องค์ประกอบของ ERD Entity A person, place, event, or thing about which data is collected บุคคล สถานที่ เหตุการณ์ หรื อ สิ่ งของที่เราจะทาการรวบรวมข้อมูล Must be multiple occurrences to be an entity สิ่ งที่จะเป็ น Entity ต้องมี Instance มากกว่า 1 Instance Example: If a firm has only one warehouse, the warehouse is not an entity. ตัวอย่างเช่น ถ้าบริ ษทหนึ่งมี คลังสิ นค้า (warehouse) เพียงแห่ง ั เดียว warehouse ก็ไม่เป็ น Entity However, if the firm has several warehouses, the warehouse could be an entity if the firm wants to store data about each warehouse instance. 5-3
  • 4. อย่างไรก็ตาม ถ้าบริ ษทที่หลาย warehouse แล้ว warehouse ก็ ั สามารถเป็ น Entity ได้ ถ้าบริ ษทต้องการเก็บข้อมูลเกี่ยวกับค่าจริ ง ั (Instance) แต่ละค่าของ warehouse Entities and Instances Attributes (Element, Property, Field) Information captured about an entity รายละเอียดเกี่ยวกับ Entity Only those used by the organization should be included in the model เฉพาะที่องค์กรต้องการใช้เท่านั้นที่จะใส่ไว้ในแบบจาลอง Attribute names are nouns ชื่อของ Attribute ต้องเป็ นคานาม Sometimes entity name is added at the beginning of the attribute name for clarity ็ บางทีกใส่ชื่อ Entity ไว้ขางหน้าชื่อ Attribute เพื่อให้ทาให้เห็นชัดเจน ้ เช่น subject_name, student_name, customer_add 5-4
  • 5. Relationships ความสั มพันธ์ Associations between entities เป็ นความสัมพันธ์ระหว่าง Entity The first entity in the relationship is the parent entity; the second entity in the relationship is the child entity Entity แรกในความสัมพันธ์เรี ยกว่า Parent Entity (Entity พ่อแม่) และ Entity ที่สองเรี ยกว่า Child Entity (Entity ลูก) Relationships should have active verb names ชื่อความสัมพันธ์ควรเป็ นคากริ ยา Relationships go in both directions ความสัมพันธ์จะเป็ นแบบสองทิศทาง Cardinality Cardinality Refers to the number of times instances in one entity can be related to instances in another entity หมายถึง จานวนของ Instance ของ Entity หนึ่งที่สามารถจะ ั สัมพันธ์กบ Instance ของอีก Entity หนึ่งได้ One instance in an entity refers to one and only one instance in the related entity (1:1) ั ถ้า Instance หนึ่ง ของ Entity หนึ่งไปสัมพันธ์กบ Instance ของอีก Entity หนึ่ งเพียงตัวเดียวเท่านั้น เรี ยกว่า มีความสัมพันธ์แบบ 1 ต่อ 1 (One-to-one relationship) เขียน แทนด้วยสัญลักษณ์ 1:1 1 1 One instance in an entity refers to one or more instances in the related entity (1:N) 5-5
  • 6. ถ้า Instance หนึ่ง ของ Entity หนึ่งไปสัมพันธ์กบ หนึ่ง หรื อมากกว่าหนึ่ง Instance ของอีก Entity หนึ่ง เรี ยกว่า มีความสัมพันธ์แบบ 1 ต่อ N (One-to-many relationship) เขียนแทนด้วยสัญลักษณ์ 1:N 1 N Customer bought Product One or more instances in an entity refer to one or more instances in the related entity (M:N) ถ้า Instance หนึ่ง หรื อมากกว่า หนึ่ง ของ Entity หนึ่งไป ั สัมพันธ์กบ หนึ่งหรื อมากกว่าหนึ่ง Instance ของอีก Entity หนึ่ง เรี ยกว่า มีความสัมพันธ์แบบ M ต่อ N (Many-to-many relationship) เขียนแทนด้วยสัญลักษณ์ M:N M Reserves N Passenger Flight Seat On 5-6
  • 7. สัญลักษณ์ที่ใช้ แทน Cardinality ของ Relation Cardinality Minimum Minimum Graphic Interpretation Instances Instances Notation Exactly one 1 1 Zero or one 0 1 One or more 1 Many (>1) Zero or more 0 Many (>1) More than one >1 >1 5-7
  • 8. ตัวอย่างของการเขียน ERD อีกแบบหนึ่ง BUILDING AN ENTITY-RELATIONSHIP DIAGRAM (ERD) (การสร้ าง ERD) Steps in Building ERDs ขั้นตอนในการสร้าง ERD Identify the entities กาหนด Entity Add attributes เพิ่ม Attribute Identify relationships กาหนดความสัมพันธ์ 5-8
  • 9. Identify the Entities Identify major categories of information กาหนดกลุ่มของสารสนเทศที่สาคัญ If available, check the DFD for data stores, external entities, and data flows ถ้าเป็ นไปได้ ตรวจสอบกับ DFD เพื่อดู Data Store, External Entity และ Data Flow Verify that there is more than one instance of the entity that occurs in the system ตรวจสอบ Entity ให้แน่ใจว่ามีค่า Instance เกิดขึ้นในระบบมากกว่า 1 ค่า Add Attributes Identify attributes of the entity that are relevant to the system under development กาหนด Attribute ของ Entity ที่สอดคล้องกับระบบที่กาลังพัฒนา Check the DFD for details on data flows and data stores ตรวจสอบ DFD เพื่อดูรายละเอียดเกี่ยวกับ Data Store และ Data Flow เพื่อดูความสอดคล้องกัน Check the data requirements of the user requirements ตรวจสอบความต้องการด้านข้อมูล ตามที่ระบุไว้ในความต้องการ ของผูใช้ ้ Interview knowledgeable users สัมภาษณ์ผใช้ที่มีความรู้เกี่ยวกับเรื่ องนั้น ๆ ู้ Perform document analysis on existing forms and reports วิเคราะห์เอกสารที่มีอยู่ เช่น แบบฟอร์ม และรายงาน Identify Relationships Start with an entity and identify all entities with which it shares relationships เริ่ มด้วยการระบุ Entity ขึ้นมา Entity หนี่งแล้วหา Entity ทั้งหมดที่มี ั ความสัมพันธ์กบมัน Describe the relationship with the appropriate verb phrase กาหนดความสัมพันธ์ดวยวลีที่มีคากริ ยาที่เหมาะสม ้ 5-9
  • 10. Determine the cardinality by discussing the business rules with knowledgeable users พิจารณา Cardinality ตามกฎเกณฑ์ ร่ วมกับผูใช้ที่มีความรู้ในเรื่ องที่ ้ เกี่ยวข้อง ERD Building Tips (กลเม็ดในการสร้ าง ERD) Data stores of the DFD should correspond to entities Data stores ของ DFD ควรจะสอดคล้องกับ Entity ต่าง ๆ Only include entities with more than one instance of information คง Entity ที่มีค่าของ Instance มากกว่า 1 ค่า ไว้ เท่านั้น 5-10
  • 11. VALIDATING AN ERD (การตรวจสอบความถูกต้องของ ERD) ***** Design Modeling Guidelines Summary (สรุ ปหลักการในการสร้างแบบจาลอง) สรุปแนวทางในการเขียน ERD 1. Entity ประเทศ ที่มีชื่อเพียง 1 Instance (เช่น เม็กซิ โก) Entity นี้ ก็ ไม่จาเป็ นต้องมี ่ 2. ถ้าเรี ยกครู วา Professor แล้วใน ERD ก็ควรจะมี Entity ที่ชื่อ Professor เพื่อให้มีความคงเส้นคงวา 3. ทาไมต้องเก็บข้อมูลเกี่ยวกับมหาวิทยาลัยทั้งหมด? จาเป็ นต้องเก็บชื่อ คนก่อตั้ง และอธิการบดีคนแรกของแต่ละมหาวิทยาลัยด้วยหรื อ? ถ้าไม่ ็ จาเป็ น Attribute เหล่านี้กควรจะเอาทิ้งไปจาก ERD 5-11
  • 12. 4. ชื่อ Attribute ใน Entity ที่ชื่อ Subject มีการเขียนที่ไม่ดี เช่น name เพราะว่าถ้าใครเห็นเดี่ยว ๆ จะไม่มีทางทราบเลยว่ามันอยูใน ่ Entity ใด จะเป็ นการดี ถ้าเริ่ มต้นแต่ละ Attribute ด้วยคาว่า SUB ตัวอย่าง name ก็แก้เป็ น SUB_name จะสื่ อดีกว่า และ area ก็ เช่นเดียวกัน ถ้าแทนด้วย department หรื อ สาขาของการวิจย ก็จะ ั สื่ อได้ดีกว่าเช่นเดียวกัน 5. Attribute ที่ชื่อ name ควรจะแยกเป็ น Last_name กับ First_name มิเช่นนั้น อาจเกิดปั ญหาในการจัดการข้อมูลภายหลัง ่ เช่น ไม่สามารถเรี ยงนามสกุลได้ ถ้ามันอยูรวมกับชื่อ 6. Model นี้ แสดงให้เห็นว่า ครู แต่ละคนสามารถทางานได้ 1 มหาวิทยาลัยเท่านั้น แล้วครู ที่ตองสอนหลายมหาวิทยาลัยจะทาอย่างไร ้ ควรจะต้องมีการบอกเงื่อนไขไว้ใน Model หรื อ ในเอกสารเพื่อให้ เกิดความชัดเจนว่ามีขอตกลงอย่างไร ้ -------------- 5-12
  • 13. YOUR TURN 1. การวิเคราะห์ และสร้ าง ERD จากแบบฟอร์ ม Welsh Clothing Order form Order Number: AB1242 Customer Number: C5432 Order Date: 22/2/2003 Customer Name: Dai the Death Customer Address: 123 Rama VRoad, Dusit, Bkk. 11300 Item number Description Quantity Price (Baht) Cost (Baht) 234 Green socks 4 20.00 80.00 532 Yellow hats 5 30.00 150.00 653 Purple shirts 3 200.00 600.00 Cost of Order: 830.00 Vat: 58.10 Total Cost: 888.10 จากใบสังสิ นค้าที่กาหนดให้ จงทาสิ่ งต่อไปนี้ (สร้าง ERD) ่ 1. วิเคราะห์หา Entity 2. หา Attribute 3. สร้างความสัมพันธ์ระหว่าง Entity 4. กาหนด Cardinality 5-13
  • 14. 2. การวิเคราะห์ และสร้ าง ERD จากรายงาน Handy Tool Ltd. Monthly Salesperson Report Salesperson number: 1001 Date: May 2006 Salesperson name: Somsak Pakdee Sales area: West Customer Customer Warehouse Warehouse Sales number name code location 101 Smith & Co. 2 Bilston 12,950.00 102 Jones & Son 4 Oxley 21,255.00 103 Smithsons 7 Parklane 10,199.80 Total monthly sales 44,404.80 จากรายงานยอดขายประจาเดือนของพนักงานขาย จงทาสิ่งต่อไปนี้ (สร้าง ERD) 1. วิเคราะห์หา Entity 2. หา Attribute 3. สร้างความสัมพันธ์ระหว่าง Entity 4. กาหนด Cardinality 5-14