Jump to content

Syntax Issue in Stored Procedure?


random1

Recommended Posts

Hey All,

 

The following runs fine:

 

CREATE DEFINER=`root`@`localhost` PROCEDURE `procedure_admin_reset_autoincrement`(IN `tableName` VARCHAR(100), IN `incrementInteger` INT)
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT 'Resets the AUTO_INCREMENT value for a table'
BEGIN
ALTER TABLE tableName
AUTO_INCREMENT = 1;
END

 

But when I try changing "= 1" to "= incrementInteger" it fails:

 

jtsLf9uUPE9En.jpg

 

Am I missing something really obvious? :S :B Is an auto_increment value strongly typed?

Link to comment
Share on other sites

Based on the error I am going to guess that the value has to be a constant integer and not a variable.

 

That's not the only problem you have though.  You can't parameterize a table name like that.  Your procedure will try and alter quite literally the table called `tableName` and not whatever you pass in as that parameter.

 

Why are you trying to create this procedure anyway?  It's only a single line of SQL to do what you want to do, the procedure does not really save you anything.  I'd also question why your wanting to change the auto-increment value in the first place.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.