alter table customer add x1 char(200)我在SQL执行这个字段, 我想添加 字段x60-x1000  请问应该怎么写

解决方案 »

  1.   


    额。。  不能批量添加吗。。或者有没有办法一次运行多条SQL 我想增加1000个字段··如果全手动一条一条写估计要3小时··
      

  2.   


    DECLARE @sql NVARCHAR(400),@i INT
    SET @i=60
    WHILE @i<=100
    begin
    SET @sql=N'alter table customer add x'+CONVERT(NVARCHAR(10),@i)+'char(200)'
    PRINT @sql
    SET @i=@i+1
    END
    /*alter table customer add x60char(200)
    alter table customer add x61char(200)
    alter table customer add x62char(200)
    alter table customer add x63char(200)
    alter table customer add x64char(200)
    alter table customer add x65char(200)
    alter table customer add x66char(200)
    alter table customer add x67char(200)
    alter table customer add x68char(200)
    alter table customer add x69char(200)
    alter table customer add x70char(200)
    alter table customer add x71char(200)
    alter table customer add x72char(200)
    alter table customer add x73char(200)
    alter table customer add x74char(200)
    alter table customer add x75char(200)
    alter table customer add x76char(200)
    alter table customer add x77char(200)
    alter table customer add x78char(200)
    alter table customer add x79char(200)
    alter table customer add x80char(200)
    alter table customer add x81char(200)
    alter table customer add x82char(200)
    alter table customer add x83char(200)
    alter table customer add x84char(200)
    alter table customer add x85char(200)
    alter table customer add x86char(200)
    alter table customer add x87char(200)
    alter table customer add x88char(200)
    alter table customer add x89char(200)
    alter table customer add x90char(200)
    alter table customer add x91char(200)
    alter table customer add x92char(200)
    alter table customer add x93char(200)
    alter table customer add x94char(200)
    alter table customer add x95char(200)
    alter table customer add x96char(200)
    alter table customer add x97char(200)
    alter table customer add x98char(200)
    alter table customer add x99char(200)
    alter table customer add x100char(200)
    */
      

  3.   


    DECLARE @sql NVARCHAR(400),@i INT
    SET @i=60
    WHILE @i<=100
    begin
    SET @sql=N'alter table customer add x'+CONVERT(NVARCHAR(10),@i)+' char(200)'
    PRINT @sql
    SET @i=@i+1
    END
      

  4.   


    不好意思。。请问一下这个是在哪里运行呢
    我在PHPMYADMIN里  不能在SQL执行
      

  5.   

    写清楚环境嘛...这些是在SQLServer里面执行的
      

  6.   

    我在MYSQL 里直接执行SQL 显示这个错误··
      

  7.   

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @sql NVARCHAR(400),@i INT SET @i=60 WHILE @i<=100 begin SET @sql=N'alter' at line 1
      

  8.   

    看到PHPADMIN我就知道是mysql,不过以为SQLServer也能用而已,你干嘛不发到mysql专区呢?mysql和php都不怎么会。算了,帮你转区,结贴时记得给点分上面的人,是你发错地方浪费别人时间。
      

  9.   

    delimiter $$
    CREATE procedure addfi()
    begin
    DECLARE asql VARCHAR(400);
    DECLARE i INT;
    SET i=60;
    WHILE i<=100 do
    SET asql=concat('alter table customer add x',i,' char(200)');
    select asql;
    set @asql=asql;
    prepare stml from @asql;
    execute stml;
    SET i=i+1;
    end while;
    END$$
    delimiter ;
      

  10.   

    错误
    SQL 查询: delimiter $$ CREATE PROCEDURE addfi( ) BEGIN DECLARE asql VARCHAR( 400 ) ;MySQL 返回: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delimiter $$
    CREATE procedure addfi()
    begin
    DECLARE asql VARCHAR(400)' at line 1 
    你好。。我运行了他提示错误···
      

  11.   

       1、最简单的办法,在MySQL的连接字符串中设置allowMultiQueries参数置为true。
        2、在程序中对SQL语句以分号拆分成多条SQL语句,然后使用Statement的addBatch方法,最后executeBatch就行。
    我查到设置是在这里 但是我找不到从哪里进入这个选项··
      

  12.   

    字段x60-x1000  char(200)MYSQL不支持这么大的表。
      

  13.   

    在MYSQL 命令行下输入,在5.5下测试通过