following is a trigger which I created in MySQL Workbench and the related tables are below as well. the trigger works perfectly in workbench but when I try to created the same trigger in phpMyAdmin, it gives me the follow error
Error
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unknown Punctuation String @ 11 STR: // SQL: delimiter // CREATE TRIGGER log_user_delete BEFORE DELETE ON user FOR EACH ROW BEGIN INSERT INTO log_user(user_id, first_name, last_name, contact_no, user_type, email, password, active, modified_by, modified_on, modified_from) SELECT user_id, first_name, last_name, contact_no, user_type, email, password, active, modified_by, modified_on, modified_from FROM user WHERE OLD.user_id = user_id;
SQL query: Documentation
delimiter // CREATE TRIGGER log_user_delete BEFORE DELETE ON user FOR EACH ROW BEGIN INSERT INTO log_user(user_id, first_name, last_name, contact_no, user_type, email, password, active, modified_by, modified_on, modified_from) SELECT user_id, first_name, last_name, contact_no, user_type, email, password, active, modified_by, modified_on, modified_from FROM user WHERE OLD.user_id = user_id;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delimiter //
CREATE TRIGGER log_user_delete
BEFORE DELETE ON user
FOR EACH ROW' at line 1.
what am I doing wrong?
2 tables :-
CREATE TABLE user (
user_id INT(11) NOT NULL AUTO_INCREMENT,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
contact_no VARCHAR(25) NOT NULL,
user_type VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
password VARCHAR(100) NOT NULL,
active INT(1) NOT NULL,
modified_by INT(11) NOT NULL,
modified_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
modified_from VARCHAR(20) NOT NULL,
PRIMARY KEY (user_id)
);
CREATE TABLE log_user (
log_id INT(11) NOT NULL AUTO_INCREMENT,
user_id INT(11) NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
contact_no VARCHAR(25) NOT NULL,
user_type VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
password VARCHAR(100) NOT NULL,
active INT(1) NOT NULL,
modified_by INT(11) NOT NULL,
modified_on DATETIME,
modified_from VARCHAR(20) NOT NULL,
log_modified_by INT(11) NOT NULL,
log_modified_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
log_modified_from VARCHAR(20) NOT NULL,
status VARCHAR(10) NOT NULL,
PRIMARY KEY (log_id)
);
Trigger :
DELIMITER //
CREATE TRIGGER log_user_delete
BEFORE DELETE ON user
FOR EACH ROW
BEGIN
INSERT INTO log_user(user_id, first_name, last_name, contact_no, user_type, email, password, active, modified_by, modified_on, modified_from) SELECT user_id, first_name, last_name, contact_no, user_type, email, password, active, modified_by, modified_on, modified_from FROM user WHERE OLD.user_id = user_id;
UPDATE log_user SET status = 'DELETED' WHERE log_id = last_insert_id();
END;
// DELIMITER ;