Question

I am trying to make a query to create several procedures at the same time; however when I try to drop them at the beginning is throws a 1064 error and only considered the first procedure query.

It creates the procedures perfectly when I try to run it separately but it stops when I do it together it stops in after the first drop

DROP PROCEDURE IF EXISTS add;
DROP PROCEDURE IF EXISTS remove;
DROP PROCEDURE IF EXISTS edit;

#PROCEDURE TO ADD  
DELIMITER //
CREATE PROCEDURE add
(p_Name VARCHAR(30), p_Quantity DECIMAL(6,2), p_QuantityType VARCHAR(5), p_Notes VARCHAR(50))

BEGIN
    INSERT INTO table
    (name, quantity, quantity_type, notes)
    VALUES
    (p_Name, p_Quantity, p_QuantityType, p_Notes);  
    COMMIT;
    END //
DELIMITER;

#PROCEDURE TO REMOVE BASED ON THE INVENTORY ITEM ID 
DELIMITER //
CREATE PROCEDURE remove
( p_Id SMALLINT(4))

BEGIN
    DELETE FROM table
        WHERE id=p_Id;

    COMMIT;
    END//
DELIMITER ;

#PROCEDURE TO EDIT BASED ON THE INVENTORY ITEM ID
DELIMITER //
CREATE PROCEDURE edit
(p_Name VARCHAR(30), p_Id SMALLINT(4))

BEGIN
    UPDATE table
        SET name=p_Name
        WHERE id=p_Id;

    COMMIT;
    END //
DELIMITER ;

No correct solution

OTHER TIPS

The recommendation is to avoid using reserved words (add, table) or give special treatment. See 9.3. Reserved Words.

SQL Fiddle demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top