Denne kode vil oprette procedure for dig:
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;
Så kan du kalde CALL tbl_wth_ai(2);
sende parameteren inden for parentes.
For eksempel:
CALL tbl_wth_ai((SELECT id FROM `ttest` WHERE c1='b'));