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
https://forums.phpfreaks.com/topic/266375-syntax-issue-in-stored-procedure/
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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.