MySQL Forums :: Stored Procedures :: stored procedure with parameter create database


Advanced Search

stored procedure with parameter create database
Posted by: Karsten Lauck ()
Date: September 25, 2016 12:20PM

Hello,

I need a stored procedure that runs a SQL script to create new a new schema.
The procedure should be called with a parameter specifing the schema name.

I have created the following procedure :

--

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `db`(IN name CHAR(20))
BEGIN
CREATE SCHEMA IF NOT EXISTS name;

CREATE TABLE IF NOT EXISTS name.`test` (
`test` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`test`));

END

--

now when i call the procedure

call db('test');

it creates a schmema called name, ignoring my parameter.

My question now is, what i am doing wrong and what i need to change, that the procedure creates a schema with the name of the parameter

Options: ReplyQuote


Subject Views Written By Posted
stored procedure with parameter create database 2440 Karsten Lauck 09/25/2016 12:20PM
Re: stored procedure with parameter create database 280 Peter Brawley 09/25/2016 12:59PM


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.