美文网首页
MYSQL可重复执行脚本添加索引,字段

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

作者: _li | 来源:发表于2022-02-19 19:46 被阅读0次

    添加字段

    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;

    相关文章

      网友评论

          本文标题:MYSQL可重复执行脚本添加索引,字段

          本文链接:https://www.haomeiwen.com/subject/zivplrtx.html