0
CREATE PROCEDURE reset_xyz_autoincrement
BEGIN

  SELECT @max := MAX(ID)+ 1 FROM ABC; 

  PREPARE stmt FROM 'ALTER TABLE XYZ AUTO_INCREMENT = ?'
  EXECUTE stmt USING @max 

  DEALLOCATE PREPARE stmt;

END $$

I took the code from here: How to Reset an MySQL AutoIncrement using a MAX value from another table?

This is the MySQL output:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEGIN

  SELECT @max := MAX(ID)+ 1 FROM ABC' at line 2 
Community
  • 1
  • 1
Marti Markov
  • 746
  • 6
  • 25

3 Answers3

1

try this

     CREATE PROCEDURE reset_xyz_autoincrement
          (username varchar(64),password varchar(64))     // here you use your columns
      BEGIN

EDIT:

try this

     DROP PROCEDURE IF EXISTS reset_xyz_autoincrement;
     CREATE PROCEDURE reset_xyz_autoincrement (userid INT)
      BEGIN
echo_Me
  • 37,078
  • 5
  • 58
  • 78
1

You should do follow:

  1. Use function brace
  2. Use semicolon every statement.

delimiter $$
CREATE PROCEDURE reset_xyz_autoincrement() BEGIN

      SELECT @max:=MAX(ID)+ 1 FROM Company_Master; 

      PREPARE stmt FROM 'ALTER TABLE Dept_Master AUTO_INCREMENT = ?';
      EXECUTE stmt USING @max ;

      DEALLOCATE PREPARE stmt;

    END$$
Dhinakar
  • 4,061
  • 6
  • 36
  • 68
0

Try adding delimiter $$ before the CREATE PROCEDURE statement.

EDIT:

I lost track in the comments on what is the current version of your procedure, but there is an error on your SELECT statement:

SELECT @yourVar := MAX(ID)+ 1 FROM ABC;

should become

SELECT MAX(ID) + 1 INTO @yourVar FROM ABC;

Plus, I think you should DECLARE myVar INT (assuming it's an Integer) before, and please notice that max is also a MySQL keyword, so I would avoid using that name in my procedure.

Cynical
  • 9,328
  • 1
  • 15
  • 30
  • I tried it even before posting but still no luck. I get and error again: `#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEGIN SELECT @max := MAX(id)+ 1 FROM movies; PREPARE stmt FROM 'ALTER TABL' at line 2` I also tried it with `delimiter ;` no luck too... – Marti Markov Dec 17 '12 at 11:49