1

Could anyone tell me that what is the syntax error in this trigger

DELIMITER |

CREATE TRIGGER User_XEntity_Before_Delete

BEFORE DELETE

   ON UserXEntity FOR EACH ROW

BEGIN

   -- Insert record into Delete_UserXEntity table
   INSERT INTO Delete_UserXEntity
   ( DeletedUserXEntityId,
     UserId,
     CreatedAt)
   VALUES
   ( OLD.Id,
     OLD.UserId,
     NOW() );

END;

|

DELIMITER ;
1
  • Trigger looks good, are you adding it on mysql terminal or some other client like phpmyadmin ? Commented Dec 4, 2014 at 6:32

1 Answer 1

1

I've got the solution. Actually I was entering this code in phpmyadmin Trigger window, where it asks about table name, time and event already. So we only need to write the trigger action code in that window. I was writing the whole trigger code and that's why I was giving me a syntax error.

We only need to write the following code in PHPMYADMIN add new trigger windows:

INSERT INTO Delete_UserXEntity
   ( DeletedUserXEntityId,
     UserId,
     CreatedAt)
   VALUES
   ( OLD.Id,
     OLD.UserId,
     NOW() );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.