Back to the 2024 paper

Unit 2: Relational Query Languages

20247m

Describe the importance of data integrity in a database. How can constraints (such as primary keys and foreign keys) help enforce integrity?

Worked SolutionAI Assisted

Importance of Data Integrity and Constraints:

Data Integrity ensures accuracy, consistency, reliability of data - prevents invalid entries, maintains business rules. Without integrity, database contains garbage, queries wrong, application fails.

Constraints enforce integrity declaratively:

  • Primary Key (Entity Integrity): Uniquely identifies row, prevents duplicates/NULL. Example: Student rollno PK ensures no duplicate student.

  • Foreign Key (Referential Integrity): Ensures reference exists or NULL, prevents orphan. Example: Enroll(s_id) FK references Student, cannot enroll non-existent student, cascade delete maintains.

  • NOT NULL, UNIQUE, CHECK, DEFAULT, Domain constraints: Enforce valid ranges, e.g., CHECK (age>0), salary >0.

  • Benefits: Centralized enforcement, not reliant on app code, prevents anomalies, automatic validation, easier maintenance. Example without PK, duplicate inserts cause inconsistency.

Similar questions

Free AppAndroid App

Coursify Android App

Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.