if exists (select 1 from information_schema.columns where table_name='role' and column_name='name')
create procedure sp() begin if not exists (select 1 from information_schema.columns where table_name='role' and column_name='name') then ALTER TABLE role add column name varchar (32) not null ; end if; end
用 #2楼 的方法,先判断一下,然后再添加。create procedure sp() begin if not exists (select 1 from information_schema.columns where schema='db1' and table_name='role' and column_name='name') then ALTER TABLE role add column name varchar (32) not null ; end if; end
create procedure sp()
begin
if not exists (select 1 from information_schema.columns where table_name='role' and column_name='name') then
ALTER TABLE role add column name varchar (32) not null ;
end if;
end
begin
if not exists (select 1 from information_schema.columns where schema='db1' and table_name='role' and column_name='name') then
ALTER TABLE role add column name varchar (32) not null ;
end if;
end