一个表有10个字段,字段的数据类型不相同,
能否像alter table test alter  column name char(100)
一样一次性把表里的所有的数据类型改为varchar的
谢谢 

解决方案 »

  1.   


    create table test2012 (col1 int,col2 int,col3 int)SELECT 'alter table test2012 alter column '+name+' char(100)' 
    from syscolumns where id=object_id('test2012')
    /*
    alter table test2012 alter column col1 char(100)
    alter table test2012 alter column col2 char(100)
    alter table test2012 alter column col3 char(100)
    */
    --动态拼接,然后exec
      

  2.   

    SELECT 'alter table tablename alter column '+name+' varchar(100)' 
    from syscolumns where id=object_id(tablename)
    把执行结果复制出来执行就可以了