Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> SQL

RDBMS Terminologies (คำศัพท์พื้นฐาน RDBMS)


คำศัพท์ RDBMS รวมถึง Database, Table, Columns เป็นต้น มาดูทีละอย่าง

1. Database (ฐานข้อมูล)

คอลเลกชันของตาราง เช่น <Student>, <Professors>, ฯลฯ

2. Table (ตาราง)

คอลเลกชันของแถว (rows) และคอลัมน์ (columns)

StudentId StudentName StudentRank
052 Tom 1
035 David 2
077 John 3

3. Column (คอลัมน์ / Field / Attribute)

คอลัมน์ในตาราง

RDBMS Terminologies (คำศัพท์พื้นฐาน RDBMS)

4. Row (แถว / Tuple / Record)

แถวใน RDBMS เรียกว่า Tuple

Relation ในฐานข้อมูลมี rows และ columns

RDBMS Terminologies (คำศัพท์พื้นฐาน RDBMS)

5. Primary Key (คีย์หลัก)

ทุกตารางมี Primary Key 1 ตัว ไม่สามารถเป็น NULL ได้

ตัวอย่าง: ProjectID เป็น Primary Key ใน Project Table เนื่องจากระบุโปรเจกต์ได้อย่างเฉพาะเจาะจง:

ProjectID ProjectName
P01 Cluster Grouping System
P02 Hospital Management System

6. Foreign Key (คีย์ต่างประเทศ)

ใช้ลิงก์ 2 ตาราง อ้างอิง Primary Key ในอีกตาราง

ตัวอย่าง: Employee table มี DEPT_ID เป็น Foreign Key ลิงก์ไป Department table

Department table มี Primary Key คือ DEPT_ID

7. Super Key (ซูเปอร์คีย์)

แอตทริบิวต์ (หรือชุดแอตทริบิวต์) ที่ระบุ tuple ได้อย่างเฉพาะเจาะจง เป็น superset ของ Candidate Key

8. Composite Key (คีย์รวม)

Primary Key ที่มีแอตทริบิวต์ 2 ตัวขึ้นไป การรวม 2 คอลัมน์ขึ้นไป

สรุปความสัมพันธ์ของ Keys

  • Super Key ⊇ Candidate Key ⊇ Primary Key
  • Alternate/Secondary Key = Candidate Key - Primary Key
  • Foreign Key อ้างอิง Primary Key ของตารางอื่น
  • Composite Key = Primary Key ที่มีหลาย columns