Is the SQL trigger coded correctly?

Is the trigger in the following SQL script correctly worded?

Here is the script.

Partial script is included.

CREATE INDEX StudentProgram ON student(StudentProgram);

USE college;

CREATE VIEW computer_science_students AS

SELECT * FROM college.student

WHERE StudentProgram = 'Computer Science';

create table professor_audit_trail (

id int unsigned primary key auto_increment not null,

ProfessorName VARCHAR(255) not null,

ProgramName VARCHAR(255) not null);

DELIMITER $$

CREATE TRIGGER save_profinfo_upon_delete

   BEFORE DELETE ON professor

   FOR EACH ROW

BEGIN

   INSERT INTO professor_audit_trail

   SET ProfessorName = professor.ProfessorName,

   ProgramName = professor.ProfessorProgram;

END$$

DELIMITER ;

1 Answer

Relevance
  • 1 month ago

    Use the "OLD" context instead of the "professor" qualifier to refer to the "professor" table fields. Pay attention also to the definition of the trigger: the END, for example, refers to the BEGIN.

    • Login to reply the answers
Still have questions? Get your answers by asking now.