Deze code creëert een procedure voor u:
CREATE PROCEDURE `tbl_wth_ai`(IN `ai_to_start` INT)
BEGIN
SET @s=CONCAT('CREATE TABLE IF NOT EXISTS `table_name` (
`id` mediumint(6) unsigned NOT NULL AUTO_INCREMENT,
`columnOne` tinyint(1) NOT NULL,
`columnTwo` int(12) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT = ', `ai_to_start`);
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END;
Dan kunt u CALL tbl_wth_ai(2);
. bellen de parameter tussen haakjes doorgeven.
Bijvoorbeeld:
CALL tbl_wth_ai((SELECT id FROM `ttest` WHERE c1='b'));