I want to take advantage of cascading with the database, so deleting a record causes all foreign references to be deleted
To ensure referential integrity database developers employ primary and foreign keys to ensure related tables maintain their integrity. As an example, two tables representing an employer and employee will often have a foreign key in the employee table which references the primary key in the employer table. An application developer can then use the foreign key in the employee table to locate the record in the employer table to identify who employs him/her. Attempts to delete the employer record when employee records are still referencing the record will cause the database to throw an error (as it should as it's maintaining referential integrity). In some circumstances this may not be desirable, so deleting employer records will cause all referencing records in the employee table to be deleted. The mechanism is 'on delete cascade'. An example of how to create this relationship is shown below:
CREATE TABLE employer(employer_id INT PRIMARY KEY,
name VARCHAR(100))
CREATE TABLE employee(employee_id INT PRIMARY KEY,
employer_id INT,
name VARCHAR(100),
CONSTRAINT employer_id_fk FOREIGN KEY(employer_id) REFERENCES employer(employer_id) ON DELETE CASCADE
Clearly, the employer_id field in the employee table references the employer_id field in the employer table. Deletions of employers will result in all related records in the employee table to be automatically deleted.