Select the product you need help with
การกำหนดความสัมพันธ์ระหว่างตารางในฐานข้อมูล Microsoft Accessหมายเลขบทความ (Article ID): 304466 - ผลิตภัณฑ์ที่เกี่ยวข้องในบทความนี้ ฝึกหัด: ต้องทราบของอินเทอร์เฟซสำหรับผู้ใช้บนคอมพิวเตอร์เครื่องเดียวที่ผู้ใช้ บทความนี้สามารถใช้ได้เฉพาะกับฐานข้อมูล Microsoft Access (.mdb หรือ.accdb) สำหรับรุ่น Microsoft Access 2000 ของบทความนี้ ดู304467
(http://support.microsoft.com/kb/304467/
)
.สำหรับข้อมูล Microsoft Access 97 รุ่นของบทความนี้ ดู304468
(http://support.microsoft.com/kb/304468/
)
.เนื้อหาบนหน้านี้สรุปบทความนี้อธิบายวิธีการกำหนดความสัมพันธ์ในฐานข้อมูล Microsoft Access รวมหัวข้อต่อไปนี้:
ข้อมูลเพิ่มเติมสิ่งที่มีความสัมพันธ์ของตารางในฐานข้อมูลที่เกี่ยว ความสัมพันธ์ช่วยให้คุณสามารถป้องกันไม่ให้ข้อมูลที่ซ้ำซ้อน ตัวอย่างเช่น ถ้าคุณกำลังออกแบบฐานข้อมูลที่จะติดตามข้อมูลเกี่ยวกับสมุดบัญชี คุณอาจมีตารางชื่อเรื่องที่เรียกว่าที่เก็บข้อมูลเกี่ยวกับสมุดบัญชีแต่ละ เช่นชื่อเรื่องของสมุดบัญชี วันที่ของการเผยแพร่ และผู้เผยแพร่ ไม่มีข้อมูลที่คุณอาจต้องการเก็บไว้เกี่ยวกับผู้เผยแพร่ เช่นหมายเลขโทรศัพท์ของผู้เผยแพร่ ที่อยู่ และรหัสไปรษณีย์ ถ้าคุณได้ถูกจัดเก็บข้อมูลนี้ทั้งหมดในตารางชื่อเรื่อง หมายเลขโทรศัพท์ของผู้เผยแพร่จะถูกทำซ้ำสำหรับแต่ละชื่อเรื่องที่พิมพ์ผู้เผยแพร่โซลูชันที่ดีกว่ามีการ เก็บข้อมูลของผู้เผยแพร่เพียงครั้งเดียวในตารางแยกจากกัน ผู้เผยแพร่ คุณจะย้ายตัวชี้ในตารางชื่อเรื่องที่อ้างอิงที่รายการในตารางผู้เผยแพร่แล้ว เมื่อต้องการตรวจสอบให้แน่ใจว่า ไม่เกิดเสียของซิงค์ข้อมูลของคุณ คุณสามารถบังคับใช้ความสมบูรณ์ของ referential ระหว่างตารางชื่อเรื่องและผู้เผยแพร่ ความสมบูรณ์ของ referential ที่ความสัมพันธ์ช่วยให้แน่ใจว่า ข้อมูลในตารางหนึ่งตรงกับข้อมูลในที่อื่น ตัวอย่างเช่น แต่ละชื่อเรื่องในตารางชื่อเรื่องต้องเกี่ยวข้องกับผู้เผยแพร่ที่ระบุในตารางผู้เผยแพร่ ชื่อเรื่องไม่สามารถเพิ่มไปยังฐานข้อมูลสำหรับผู้เผยแพร่ที่ไม่มีอยู่ในฐานข้อมูล ชนิดของความสัมพันธ์ของตารางความสัมพันธ์ที่ทำงานได้ โดยตรงกับข้อมูลในคอลัมน์คีย์ มักคอลัมน์ที่ มีชื่อเดียวกันในตารางทั้งสอง ในกรณีส่วนใหญ่ ความสัมพันธ์ที่ตรงกับคีย์หลักจากตารางหนึ่ง ซึ่งแสดงรหัสเฉพาะสำหรับแต่ละแถว ด้วยรายการในคีย์ต่างประเทศในอีกตารางหนึ่ง ตัวอย่างเช่น ขายสามารถเชื่อมโยงกับชื่อเรื่องเฉพาะที่ขาย โดยการสร้างความสัมพันธ์ระหว่างคอลัมน์ title_id ในตารางชื่อเรื่อง (คีย์หลัก) และคอลัมน์ title_id ในตารางการขาย (คีย์ภายนอก)มีอยู่สามชนิดของความสัมพันธ์ระหว่างตาราง ชนิดของความสัมพันธ์ที่สร้างขึ้นขึ้นอยู่กับวิธีกำหนดคอลัมน์ที่เกี่ยวข้อง ความสัมพันธ์แบบหนึ่งไปยังหลายความสัมพันธ์แบบหนึ่งไปยังหลายเป็นชนิดการที่พบโดยทั่วไปของความสัมพันธ์ ในชนิดนี้ของความสัมพันธ์ แถวในตารางสามารถมีหลายแถวตรงกันในตาราง B แต่แถวในตาราง B สามารถมีได้เพียงหนึ่งแถวตรงกันในตาราง A. ตัวอย่างเช่น ตารางผู้เผยแพร่และชื่อเรื่องมีความสัมพันธ์แบบหนึ่งไปยังหลาย: แต่ละผู้เผยแพร่สร้างชื่อเรื่องต่าง ๆ แต่ละชื่อเรื่องที่มาจากผู้เผยแพร่เดียวเท่านั้นมีสร้างความสัมพันธ์แบบหนึ่งไปยังหลายถ้าเดียวคอลัมน์ที่เกี่ยวข้องอย่างใดอย่างหนึ่งคือ คีย์หลัก หรือมีข้อจำกัดที่ไม่ซ้ำกัน ในการเข้าถึง ด้านคีย์หลักของความสัมพันธ์แบบหนึ่งไปยังหลาย denoted ด้วยสัญลักษณ์คีย์ ด้านข้างแป้นต่างประเทศของความสัมพันธ์ถูก denoted โดยมีสัญลักษณ์ infinity ความสัมพันธ์ของหลายไปยังหลายในความสัมพันธ์ หลายไปยังหลายแถวในตาราง A สามารถมีหลายแถวที่ตรงกันในตาราง B และในทางกลับกันได้ คุณสามารถสร้างความสัมพันธ์แบบ โดยการกำหนดตารางสาม เรียกว่าตารางเชื่อมต่อ คีย์หลักซึ่งประกอบด้วยคีย์ภายนอกจากตาราง A และตาราง B. ตัวอย่างเช่น ตารางผู้สร้างและตารางชื่อเรื่องมีความสัมพันธ์หลายไปยังหลายที่กำหนด โดยความสัมพันธ์แบบหนึ่งไปยังหลายจากแต่ละตารางเหล่านี้ไปยังตาราง TitleAuthors คีย์หลักของตาราง TitleAuthors คือ ชุดของคอลัมน์ au_id (คีย์หลักของตารางผู้สร้าง) และคอลัมน์ title_id (ชื่อเรื่องคีย์หลักของของตาราง)ความสัมพันธ์ one-To-OneIn a one-to-one relationship, a row in table A can have no more than one matching row in table B, and vice versa. A one-to-one relationship is created if both of the related columns are primary keys or have unique constraints.This type of relationship is not common because most information related in this way would be all in one table. You might use a one-to-one relationship to:
How to Define Relationships Between TablesWhen you create a relationship between tables, the related fields do not have to have the same names. However, related fields must have the same data type unless the primary key field is an AutoNumber field. You can match an AutoNumber field with a Number field only if thefieldSizeproperty of both of the matching fields is the same. For example, you can match an AutoNumber field and a Number field if thefieldSizeproperty of both fields is Long Integer. Even when both matching fields are Number fields, they must have the samefieldSizeproperty setting.How to Define a One-To-Many or One-To-One RelationshipsTo create a one-to-many or a one-to-one relationship, follow these steps:
How to Define a Many-To-Many RelationshipsTo create a many-to-many relationship, follow these steps:
ความสอดคล้องของ referentialความสมบูรณ์ของ referential คือ ระบบของกฎที่ใช้ Microsoft Access เพื่อให้แน่ใจว่า ความสัมพันธ์ระหว่างระเบียนในตารางที่เกี่ยวข้องไม่ถูกต้อง และให้คุณโดยไม่ตั้งใจไม่ลบ หรือเปลี่ยนแปลงข้อมูลที่เกี่ยวข้อง คุณสามารถตั้งค่าความสมบูรณ์ของ referential เมื่อเงื่อนไขใด ๆ ต่อไปนี้ทั้งหมดตาม:
การปรับปรุง cascading และลบFor relationships in which referential integrity is enforced, you can specify whether you want Microsoft Access to automatically cascade update or cascade delete related records. If you set these options, delete and update operations that would normally be prevented by referential integrity rules are allowed. When you delete records or change primary key values in a primary table, Microsoft Access makes the necessary changes to related tables to preserve referential integrity.ถ้าคุณคลิกเพื่อเลือกนั้นCascade Update Related Fieldscheck box when you define a relationship, any time that you change the primary key of a record in the primary table, Microsoft Access automatically updates the primary key to the new value in all related records. For example, if you change a customer's ID in the Customers table, the CustomerID field in the Orders table is automatically updated for every one of that customer's orders so that the relationship is not broken. Microsoft Access cascades updates without displaying any message. หมายเหตุ::If the primary key in the primary table is an AutoNumber field, selecting theCascade Update Related Fieldscheck box will have no effect, because you cannot change the value in an AutoNumber field. ถ้าคุณเลือกนั้นเรียงซ้อนลบระเบียนที่เกี่ยวข้องcheck box when you define a relationship, any time that you delete records in the primary table, Microsoft Access automatically deletes related records in the related table. For example, if you delete a customer record from the Customers table, all the customer's orders are automatically deleted from the Orders table (this includes records in the Order Details table related to the Orders records). When you delete records from a form or datasheet with theเรียงซ้อนลบระเบียนที่เกี่ยวข้องcheck box selected, Microsoft Access warns you that related records may also be deleted. However, when you delete records using a delete query, Microsoft Access automatically deletes the records in related tables without displaying a warning. ชนิดการเข้าร่วมThere are three join types, as follows:ตัวเลือกที่ 1defines an inner join. An inner join is a join where records from two tables are combined in a query's results only if values in the joined fields meet a specified condition. In a query, the default join is an inner join that selects records only if values in the joined fields match. ตัวเลือก 2defines a left outer join. A left outer join is a join in which all the records from the left side of the LEFT JOIN operation in the query's SQL statement are added to the query's results, even if there are no matching values in the joined field from the table on the right. Option 3defines a right outer join. A right outer join is a join in which all the records from the right side of the RIGHT JOIN operation in the query's SQL statement are added to the query's results, even if there are no matching values in the joined field from the table on the left. คุณสมบัติหมายเลขบทความ (Article ID): 304466 - รีวิวครั้งสุดท้าย: 17 กันยายน 2554 - Revision: 3.0 ใช้กับ
แปลโดยคอมพิวเตอร์ ข้อมูลสำคัญ: บทความนี้แปลโดยซอฟต์แวร์การแปลด้วยคอมพิวเตอร์ของ Microsoft แทนที่จะเป็นนักแปลที่เป็นบุคคล Microsoft มีบทความที่แปลโดยนักแปลและบทความที่แปลด้วยคอมพิวเตอร์ เพื่อให้คุณสามารถเข้าถึงบทความทั้งหมดในฐานความรู้ของเรา ในภาษาของคุณเอง อย่างไรก็ตาม บทความที่แปลด้วยคอมพิวเตอร์นั้นอาจมีข้อบกพร่อง โดยอาจมีข้อผิดพลาดในคำศัพท์ รูปแบบการใช้ภาษาและไวยากรณ์ เช่นเดียวกับกรณีที่ชาวต่างชาติพูดผิดเมื่อพูดภาษาของคุณ Microsoft ไม่มีส่วนรับผิดชอบต่อความคลาดเคลื่อน ความผิดพลาดหรือความเสียหายที่เกิดจากการแปลเนื้อหาผิดพลาด หรือการใช้บทแปลของลูกค้า และ Microsoft มีการปรับปรุงซอฟต์แวร์การแปลด้วยคอมพิวเตอร์อยู่เป็นประจำ ต่อไปนี้เป็นฉบับภาษาอังกฤษของบทความนี้:304466
(http://support.microsoft.com/kb/304466/en-us/
)
| การแปลบทความ
|




กลับไปด้านบน








