create procedure add_col(
in model_name text,
in col_name text,
in col_info text,
out result text
)
begin
if not exists( select * from information_schema.COLUMNS where TABLE_NAME = model_name and COLUMN_NAME = col_name) then
set @ddl=CONCAT('alter table ', model_name, ' add column ', col_name, col_info);
prepare stmt from @ddl;
execute stmt;
set result = 'success';
else
set result = 'exists';
end if;
end;
set @result = '';
call add_col('dc_employee','senior_1 ','tinyint(1) NULL DEFAULT 0 COMMENT "是否是高级用户,0 不是 1 是"',@result);
select @result;
存储过程添加列