Re: How do I create my table to avoid java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '' for key 'PRIMARY'
Posted by: Filipe Silva
Date: January 02, 2019 04:28AM

Hi Karen,

Cascade deletes are defined with foreign keys, not primary keys.

If that's what you really want, your `tutor_subject` table could be created like this:

CREATE TABLE tutor_subject (
tutor_id INT NOT NULL,
subjectName Varchar(50) NOT NULL,
FOREIGN KEY (tutor_id) REFERENCES tutors (tutor_id) ON DELETE CASCADE)
Engine=InnoDB Default charset=utf8mb4

This way, when you delete a tutor record from the "tutors" table, the tutor/subject records from the "tutor_subject" table are also deleted for the same "tutor_id".

IHTH

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.