MYSQL可重复执行脚本添加索引,字段

2022-02-19  本文已影响0人  _li

添加字段

drop procedure if exists add_column_if;

delimiter $$

create procedure add_column_if()

begin

declare

iCnt int;

select count(*) into iCnt from information_schema.columns

where table_schema=(select database())

and table_schema='BONDCONTRACE_TEST'

andcolumn_name='AAA';

if (iCnt=0) then

alter table bondcontrac_test add  AAA varchar(10) default null;

end if;

end;

call add_column_if;

drop procedeure add_column_if; $$

delimiter;

加索引

drop  procedure if exits add_index_id;

delimiter $$

create procedure add_index()

begin

declare iCint int;

select count(*) from information_schema.statistcs

where table_schema=''

and table_name=''

and index_name=''

and column_name in ('','')

if (iCint=0) then

alter table tablename add key index_name('','');

end if;

end'

call add_index_if;

drop procedure add_index_if;$$

delimiter;

上一篇下一篇

猜你喜欢

热点阅读