批量更改字段長度大小

create proc ChangeColumnLength
@P0 varchar(50)   --Table Name
as
Begin
 declare @Column varchar(50),@SQL varchar(max)
 declare mycursor cursor for
 select Name from syscolumns where id=OBJECT_ID(@P0) and xtype='167' and length between 1 and 50
 open mycursor
 fetch next from mycursor into @Column
 while(@@FETCH_STATUS=0)
 Begin
  set @SQL='alter Table '+@P0+' alter column '+@Column+' varchar(max) ' 
  exec(@SQL)
  fetch next from mycursor into @Column
 End
 close mycursor
 deallocate mycursor
End

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章