1

What's the right way to create in MySQL a PROCEDURE for multiple queries like this one made for SQL?

CREATE OR REPLACE PROCEDURE foo
IS
BEGIN
  -- The create sentence goes here. For example:
  -- EXECUTE IMMEDIATE
  -- 'CREATE TABLE bar (...)';

  -- The update sentence goes here
  -- EXECUTE IMMEDIATE
  -- 'UPDATE bar SET ...';

  -- The drop/delete sentence goes here.
  -- EXECUTE IMMEDIATE
  -- 'DROP TABLE bar;'
END;
NineCattoRules
  • 2,253
  • 6
  • 39
  • 84

2 Answers2

5

In MySQL just insert the 3 queries into your procedure. You need a different delimiter defined before, because otherwise the engine will terminate the procedure definition at the first ; which would make it incomplete. So change to anything else like $ or //

DELIMITER //
CREATE PROCEDURE your_proc()
BEGIN
  create ... ;
  update ... ;
  drop ... ;
END //
DELIMITER ;
juergen d
  • 201,996
  • 37
  • 293
  • 362
0
CREATE PROCEDURE foo 
    @LastName nvarchar(50), 
    @FirstName nvarchar(50) 
AS 
    QUERY1; -- SELECT or whatever
    QUERY2;
GO
Hearner
  • 2,711
  • 3
  • 17
  • 34