Use Constraints

by

in

Explanation: Constraints enforce rules at the database level, ensuring data integrity.

  • Why It Matters: They prevent invalid data from being entered and maintain relationships between tables.
  • Example: Add a foreign key constraint:
ALTER TABLE employees ADD CONSTRAINT fk_department FOREIGN KEY (department_id) REFERENCES departments(department_id);

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *