use 数据库;
DROP PROCEDURE IF EXISTS 存储过程名;
DELIMITER $$
CREATE PROCEDURE 存储过程名()
BEGIN
DECLARE i INT;
SET i = 0;
WHILE i <= 31 DO
SET @sql1 = CONCAT(
"CREATE TABLE power_saving_", i, " (
`aaa` int(11)unsigned NOT NULL COMMENT '休眠周期(1~4294967295)单位为秒',
`created_on` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;"
);
PREPARE sql1 FROM @sql1;
EXECUTE sql1;
SET i = i + 1;
END WHILE;
END$$
DELIMITER ;
CALL 存储过程名();
DROP PROCEDURE IF EXISTS 存储过程名;
// int(11)unsigned无符号存储,最大值为4294967295
// DEFAULT CURRENT_TIMESTAMP(0)数据库自动生成时间