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

添加字段

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;

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容