向指定表中添加字段
drop procedure if exists pro_AddColumn;
delimiter //
create procedure pro_AddColumn()
BEGIN
if not exists(select * from information_schema.COLUMNS where table_name='exercise'and column_name ='AGE')then
ALTER TABLE `exercise` ADD COLUMN `AGE` varchar(24) DEFAULT NULL;
end if;
end;//
delimiter ;
call pro_AddColumn();
修改字段名
drop procedure if exists pro_ChangeColumn;
delimiter //
create procedure pro_ChangeColumn()
BEGIN
if exists(select * from information_schema.COLUMNS where table_name='exercise'and column_name ='AGE') then
ALTER TABLE `exercise` CHANGE `AGE` NIAN_NIN varchar(24) DEFAULT NULL;
end if;
end;//
delimiter ;
call pro_ChangeColumn();