Constraints help maintain data integrity by enforcing rules on your tables.
CREATE TABLE enrollments (
id INTEGER PRIMARY KEY,
student_id INTEGER,
course_id INTEGER,
grade INTEGER,
CONSTRAINT fk_student FOREIGN KEY (student_id)
REFERENCES students(id),
CONSTRAINT chk_grade CHECK (grade >= 0 AND grade <= 100));
This table ensures each enrollment has a valid student reference and a grade between 0 and 100.
Using constraints is essential for building reliable databases.