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

Entity Integrity Rule ใน RDBMS


ตาม Entity Integrity Rule ทุกตารางต้องมี Primary Key และ Primary Key ไม่สามารถมีค่า NULL ได้

ตัวอย่าง

<Student>

Student_ID Student_Awards Student_Awards

Primary Key คือ Student_ID ไม่สามารถใช้ Student_Awards เป็น Primary Key ได้ เพราะไม่ใช่นักเรียนทุกคนที่ได้รางวัล (อาจเป็น NULL)

ตัวอย่างเพิ่มเติม

<Employee>

Employee_ID Employee_Name Employee_Age Employee_Location

Primary Key คือ Employee_ID

สรุป Entity Integrity Rule

  • รับรองว่าแต่ละ tuple ในตารางมีความเป็นเอก'identité
  • ทุกตารางต้องมี Primary Key (เช่น Student_ID สำหรับตาราง Student)
  • ทุก entity ต้องเป็นเอกตัว
  • Primary Key ของ relation ต้องมีค่า unique สำหรับทุกแถว
  • Primary Key ไม่สามารถเป็น NULL ได้ และต้อง unique
  • ตัวอย่าง: Employee_ID ไม่สามารถเป็น NULL ในตาราง Employee ได้