怎样将数据库中所有表中含有numeric(18,2)字段改成numeric(18,10)及将float改成numeric

怎样将数据库中所有表中含有numeric(18,2)字段改成numeric(18,10)
declare
c cursorforselect'alter table ['+ a.name +'] alter column ['+b.name+'] numeric(18,10);'from sysobjects a,syscolumns b,systypes c where a.id=b.id and b.xtype=c.xtype and a.type='u' and b.xprec=18 and b.xscale=2 and c.name in('decimal','numeric') open c declare@cvarchar(8000) fetchnextfrom c into@cwhile(@@fetch_status=0) beginexec(@c) fetchnextfrom c into@cendclose c deallocate c


将float改成numeric
declare c cursor
for
    select 'alter table ['+ a.name + '] alter column ['+b.name+'] numeric(18,2);'
    from sysobjects a,syscolumns b,systypes c
    where a.id=b.id
      and b.xtype=c.xtype
      and a.type='u'
      and b.xtype=62
      and c.name in('float')
open c
declare @c varchar(8000)
fetch next from c into @c
while(@@fetch_status=0)
    begin
        exec(@c)
        fetch next from c into @c
    end
close c
deallocate c

posted on 2012-10-18 15:25  oer  阅读(1226)  评论(0编辑  收藏  举报

导航