Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
This is possible in two steps by using a dynamic SQL: SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` ); SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @nextId[]()); PREPA...
Answer
#4: Post edited
This is possible in two steps and[]() [using a dynamic SQL](https://stackoverflow.com/questions/46622690/set-auto-increment-value-through-variable-in-mysql):- SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` );
- SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @nextId[]());
- PREPARE st FROM @sql;
- EXECUTE st;
- However, if the values fall frequently you should try to find the underlying cause.[]()
- This is possible in two steps by [using a dynamic SQL](https://stackoverflow.com/questions/46622690/set-auto-increment-value-through-variable-in-mysql):
- SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` );
- SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @nextId[]());
- PREPARE st FROM @sql;
- EXECUTE st;
- However, if the values fall frequently you should try to find the underlying cause.[]()
#3: Post edited
- This is possible in two steps and[]() [using a dynamic SQL](https://stackoverflow.com/questions/46622690/set-auto-increment-value-through-variable-in-mysql):
- SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` );
SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @max_id);- PREPARE st FROM @sql;
- EXECUTE st;
- However, if the values fall frequently you should try to find the underlying cause.[]()
- This is possible in two steps and[]() [using a dynamic SQL](https://stackoverflow.com/questions/46622690/set-auto-increment-value-through-variable-in-mysql):
- SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` );
- SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @nextId[]());
- PREPARE st FROM @sql;
- EXECUTE st;
- However, if the values fall frequently you should try to find the underlying cause.[]()
#2: Post edited
This is possible in two steps and [using a dynamic SQL](https://stackoverflow.com/questions/46622690/set-auto-increment-value-through-variable-in-mysql):- SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` );
- SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @max_id);
- PREPARE st FROM @sql;
- EXECUTE st;
However, if the values fall frequently you should try to find the underlying cause.
- This is possible in two steps and[]() [using a dynamic SQL](https://stackoverflow.com/questions/46622690/set-auto-increment-value-through-variable-in-mysql):
- SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` );
- SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @max_id);
- PREPARE st FROM @sql;
- EXECUTE st;
- However, if the values fall frequently you should try to find the underlying cause.[]()
#1: Initial revision
This is possible in two steps and [using a dynamic SQL](https://stackoverflow.com/questions/46622690/set-auto-increment-value-through-variable-in-mysql): SET @nextId = (SELECT MAX(id) + 1 FROM `CustomTable` ); SET @sql = CONCAT('ALTER TABLE `CustomTable` AUTO_INCREMENT = ', @max_id); PREPARE st FROM @sql; EXECUTE st; However, if the values fall frequently you should try to find the underlying cause.