Mysql 批量建表sql语句

DELIMITER $$
USE `yx_images_library`$$
DROP PROCEDURE IF EXISTS `yx_image_table_create`$$
CREATE DEFINER=`dev`@`%` PROCEDURE `yx_image_table_create`(
)
BEGIN
DECLARE i INT;
DECLARE table_name VARCHAR(20);
SET i = 0;
WHILE i<40 DO
SET table_name = CONCAT(‘yx_image_’,i+1);
SET @csql = CONCAT(
‘ALTER TABLE ‘,table_name,’ ADD COLUMN owner char(12) not null default \’\’ after id;’
);
PREPARE create_stmt FROM @csql;
EXECUTE create_stmt;
SET i = i+1;
END WHILE;
END$$
DELIMITER ;
— CALL yx_image_table_create();

Related Post

发表评论

电子邮件地址不会被公开。 必填项已用*标注