Summary lecture in 2110671 – Database Management System class, 06/29/2008
ต่อจาก เล็คเชอร์ที่แล้ว…
Relational Database คือกลุ่มของ relations (หรือที่ทุกคนมักเรียกกันว่า table) โดยที่ในแต่ละ table จะประกอบด้วยกลุ่มของ tuples (หรือที่เรียกว่า row, record) และมี attribute เป็นตัวกำหนดคุณสมบัติเฉพาะของแต่ละ tuple (หรือที่เรียกว่า column)
![]()
Relational Model
- ริเริ่มโดย Edgar F. Codd [1] ในปี 1969
- ปีถัดมา E. F. Codd เขียนเปเปอร์เพื่อเป็น specification [2] นิยามของ relational database (เรียกกันว่า กฎ 12 ข้อของ Codd [3]) เนื่องจากใครๆต่างก็ออกมาอ้างว่า database ที่ตนทำนั้นเป็น relational พอค๊อดออกเปเปอร์นี้มาปรากฎว่าแทบจะไม่มีใครทำตรงตามสเป๊กเลย
- SQL เป็น non-procedural languages (NPL)
- Relation = 2D table consists of Row and Column
- Tuple = Row
- Attribute = Column
- Domain = ค่าที่เป็นไปได้ทั้งหมดสำหรับ attributes เช่น column gender มี domain เป็น {male, female}
- ใน table จะต้องมี column หนึ่งที่ unique เพื่อเอาไว้จำแนกความแตกต่างของ row (Primary Key) เรื่องของ PK ที่น่าสนใจคือออกแบบยังไงไม่ให้ยาวหรือสั้นเกินไป ถ้ายาวเกินไปก็จะเปลืองเนื้อที่ ในขณะที่ถ้าสั้นเกินไปก็ใช้ไม่ได้ (overflow)
- การใส่ข้อมูลที่ใช้แบ่งประเภทเข้าไปใน PK เช่น รหัสประจำตัวนิสิต สองตัวแรกคือปีที่เข้าการศึกษา สองตัวสุดท้ายคือรหัสคณะ ทำให้เกิดปัญหา – ลองนึกภาพถ้านิสิตต้องการเปลี่ยนคณะโดยไม่เปลี่ยนรหัส – จะทำไม่ได้! เห็นได้ว่าเป็นการออกแบบที่มี High Coupling
- Table ที่เป็น entity หลักไม่ควรใช้ composite key
- PK มีไว้เพื่อทำ data integrity
- Entity integrity – แยกความแตกต่างระหว่าง row ใน table เดียวกัน
- Referential integrity
ภาพประกอบ B
An example of a database that has not enforced referential integrity. In this example, there is a foreign key (artist_id) value in the album table that references a non-existent artist — in other words there is a foreign key value with no corresponding primary key value in the referenced table.
This anomaly came about when the record for an artist called “Aerosmith”, with an artist_id of “4″, was deleted from the artist table, even though the album “Eat the rich” referred to this artist. If referential integrity had been enforced, the deletion of the main record would have been possible, but its associated record would have been deleted as well. Alternatively, the existence of an associated record would not allow the delete operation of the referenced record, and instead return an error code.
References
- [1] Edgar F. Codd: Wikipedia article
- http://en.wikipedia.org/wiki/Edgar_F._Codd
- [2] A relational model of data for large shared data banks
- http://portal.acm.org/citation.cfm?id=362685&dl=
- [3] Codd’s 12 rules
- http://en.wikipedia.org/wiki/Codd%27s_12_rules
Figures
- [A] Image:Relational db terms.png
- http://en.wikipedia.org/wiki/Image:Relational_db_terms.png
- [B] Image:Relational db terms.png
- http://en.wikipedia.org/wiki/Image:Relational_db_terms.png
4 Comments
แว๊กๆๆๆ
ไม่น่าตามมาอ่านต่อเลย
อุตส่าห์ข้ามไม่อ่านหนึ่งอัน
ทำรูปปลากรอบสวยงามด้วย อิอิ
@ju จดไว้กันลืมอ่ะ ขนาดจดเองยังอ่านไม่รู้เรื่องเลย 555
@Hana ก๊อปเค้ามาแปะนะฮะ มิได้ทำเอง ^-^