用存储过程,批量建表和批量修改表
1、批量创建表
-- 按日建立表tables_YYYYMMDD,从20200101至20211231
drop procedure if exists process_create_tables; -- 存储过程名称
delimiter //
create procedure process_create_tables() -- 存储过程名称
begin
set @tab_year=20; -- 开始年份
set @tab_month=1; -- 开始月份
set @tab_day=1; -- 开始日期
while @tab_year<=20 do -- 结束年份
while @tab_month<=12 do -- 结束月份
if (@tab_month=1 or @tab_month=3 or @tab_month=5 or @tab_month=7 or @tab_month=8 or @tab_month=10 or @tab_month=12) then
set @days=31;
elseif @tab_month=2 then
if (@tab_year%400=0 or (@tab_year%4=0 and @tab_year%100<>0)) then
set @days=29;
else
set @days=28;
end <