MySQL Forums
Forum List  »  Stored Procedures

Store procedure deletes all!
Posted by: Sam Jonhson
Date: August 01, 2012 11:10AM

DROP PROCEDURE IF EXISTS Changerole;
delimiter $
CREATE PROCEDURE Changerole (OldRole CHAR(8), Newrole CHAR(8), IdUser INT)
BEGIN
IF (OldRole="admin" AND NewRole="mod")
THEN
DELETE FROM administrators WHERE iduser=IdUser;
INSERT INTO moderators (iduser) VALUES (IdUser);
END IF;
IF (OldRole="admin" AND NewRole="user")
THEN
DELETE FROM administrators WHERE iduser=IdUser;
INSERT INTO normalusers (iduser) VALUES (IdUser);
END IF;

IF (OldRole="mod" AND NewRole="admin")
THEN
DELETE FROM moderators WHERE iduser=IdUser;
INSERT INTO administrators (iduser) VALUES (IdUser);
END IF;
IF (OldRole="mod" AND NewRole="user")
THEN
DELETE FROM moderators WHERE iduser=IdUser;
INSERT INTO normalusers (iduser) VALUES (IdUser);
END IF;

IF (OldRole="user" AND NewRole="admin")
THEN
DELETE FROM normalusers WHERE iduser=IdUser;
INSERT INTO administrators (iduser) VALUES (IdUser);
END IF;
IF (OldRole="user" AND NewRole="mod")
THEN
DELETE FROM normalusers WHERE iduser=IdUser;
INSERT INTO moderators (iduser) VALUES (IdUser);
END IF;
END; $
delimiter ;

The procedure deletes a row from a table and inserts the same row in another table. The insert works fine, but when the delete starts, the delete removes every row from the table. Why?

Options: ReplyQuote


Subject
Views
Written By
Posted
Store procedure deletes all!
1649
August 01, 2012 11:10AM
779
August 03, 2012 07:50PM


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.