z-auto-increment-0.sql 901 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. [create sort_menu]
  2. ALTER TABLE `dbr_sort_menu`
  3. MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
  4. ALTER TABLE your_table_name AUTO_INCREMENT = 0;
  5. DELIMITER //
  6. CREATE PROCEDURE ResetAutoIncrement()
  7. SQL SECURITY INVOKER
  8. BEGIN
  9. DECLARE done INT DEFAULT FALSE;
  10. DECLARE tableName VARCHAR(255);
  11. DECLARE cur CURSOR FOR
  12. SELECT table_name
  13. FROM information_schema.tables
  14. WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE';
  15. DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  16. OPEN cur;
  17. read_loop: LOOP
  18. FETCH cur INTO tableName;
  19. IF done THEN
  20. LEAVE read_loop;
  21. END IF;
  22. SET @sql = CONCAT('ALTER TABLE ', tableName, ' AUTO_INCREMENT = 0;');
  23. PREPARE stmt FROM @sql;
  24. EXECUTE stmt;
  25. DEALLOCATE PREPARE stmt;
  26. END LOOP;
  27. CLOSE cur;
  28. END //
  29. DELIMITER ;