博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Tsql一段更新所有用户表的操作

Posted on   zhu zhu  阅读(174)  评论(0编辑  收藏  举报
use USER_DB
declare @usertablename sysname
declare @sqlstr varchar(5000)
declare @newcd varchar(50)
declare @oldcd varchar(50)
declare my_cursor1 cursor for 
select name from sysobjects where xtype = 'U' order by name;
set @newcd = '0101150842020402'
set @oldcd = '0101150842020300'
open my_cursor1
fetch next from my_cursor1
into @usertablename
while @@FETCH_STATUS = 0
begin
print @usertablename
set @sqlstr = 'update '+@usertablename+' set ENTERPRISECODERF = '''+@newcd+''' where ENTERPRISECODERF = '''+@oldcd+''''
print @sqlstr
EXEC (@sqlstr)
fetch next from my_cursor1
into @usertablename
end
CLOSE my_cursor1
DEALLOCATE my_cursor1
努力加载评论中...
点击右上角即可分享
微信分享提示