Sushant
Sushant

Reputation: 635

mysql calling another procedure(of another schema) from procedure

I want to call a SP1 from a SP2. SP1 is stored in Another database schema on same PC. Please check following Snippet

    CREATE DEFINER=`root`@`localhost`  PROCEDURE `db2`.`sp2_procedure` ()
BEGIN
    call sp1_procedure(50);
END

Also tried call db1.sp1_procedure(50); Is it i am calling Wrongly or Calling SP of Other schema is not possible

Note :: SP - Stored Procedure.

Upvotes: 1

Views: 5319

Answers (1)

Hamed Kamrava
Hamed Kamrava

Reputation: 12847

You can do this simply, just mention schema name in prefix.

For instance :

CREATE DEFINER=`root`@`localhost` PROCEDURE `db1`.`sp1`()
BEGIN
select 'I am procedure from another db';
END

Next,

CREATE DEFINER=`root`@`localhost` PROCEDURE `db2`.`sp2`()
BEGIN
call db1.sp1();
END

And call that like so :

use db2;
call `db2`.sp2();

Upvotes: 2

Related Questions