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
SELECT 'alter table tablename alter column '+name+' varchar(100)' from syscolumns where id=object_id(tablename) 把执行结果复制出来执行就可以了
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
from syscolumns where id=object_id(tablename)
把执行结果复制出来执行就可以了