create procedure setDefault()
begin
if exists (select  COLUMN_NAME  from information_schema.COLUMNS where TABLE_NAME = 'admin' and COLUMN_NAME = 'isValid') then
alter table admin modify isValid tinyint(4) default 1;
end if;
end;
call setDefault();
drop procedure setDefault;上面是修改字段默认值的存储过程,但是在Linux上控制台上执行有错误,错误原因是exists导致的,单独exists括号里面的没错,有谁知道原因呀

解决方案 »

  1.   

    select  count(*) into @acount  from information_schema.COLUMNS where TABLE_NAME = 'admin' and COLUMN_NAME = 'isValid';
    if @acount>=1 then .....
      

  2.   

    delimiter $$
    create procedure setDefault()
    begin
    select  COLUMN_NAME  into @sql from information_schema.COLUMNS where table_schema='DB_name' and  TABLE_NAME = 'admin' and COLUMN_NAME = 'isValid';
    if @sql is not null
    then 
    alter table admin modify isValidtinyint(4) default 1;
    end if;
    end$$
      

  3.   

    create procedure setDefault()
    begin
    select  COLUMN_NAME  from information_schema.COLUMNS where TABLE_NAME = 'admin' and COLUMN_NAME = 'isValid';

        if FOUND_ROWS()>0 then
            alter table admin modify isValid tinyint(4) default 1;
        end if;
    end;
      

  4.   

    非常感谢了,原因是http://www.cnblogs.com/rootq/archive/2009/05/27/1490523.html,MySql中delimiter的作用。