ALTER TABLE IF EXISTS '...' ADD ....
当表存在的时候用ALTER
不存在的时候CREATE TABLE

解决方案 »

  1.   

    不如判断是否存在,存在就drop掉重建,不存在就直接创建
      

  2.   


    create procedure sp()
    begin
       if exists(SELECT table_name FROM information_schema.TABLES WHERE table_name ='yourname') then
          alter table ....;
       else
          create table ....;
       end if;
    end ;
      

  3.   


    create procedure sp()
    begin
       if exists(SELECT table_name FROM information_schema.TABLES WHERE table_name ='yourname') then
          alter table ....;
       else
          create table ....;
       end if;
    end ;
      

  4.   


    create procedure sp()
    begin
       if exists(SELECT table_name FROM information_schema.TABLES WHERE table_name ='yourname') then
          alter table ....;
       else
          create table ....;
       end if;
    end ;
      

  5.   

    一句SQL语句在MYSQL显然无法实现。 只能通过上面的存储过程来实现,或者在你的程序中来实现比较方便。
      

  6.   

    没有这样的SQL语句,用SP来实现