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括号里面的没错,有谁知道原因呀
if @acount>=1 then .....
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$$
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;