SQL遍历所有表建立临时表

--遍历所有表
declare @tmpId int
declare @tmpfiles nvarchar(127)

declare tb_Tmp cursor for
select Id,files from peopletb
open tb_Tmp
fetch next from tb_Tmp into @TmpId,@tmpfiles
WHILE @@FETCH_STATUS = 0
BEGIN
print @tmpfiles
set @tmpfiles=REPLACE(@tmpfiles,'192.168.0.102','www.zh-rc.net')
print @tmpfiles
   update peopletb set files=@tmpfiles where Id=@tmpId
   fetch next from tb_Tmp into @TmpId,@tmpfiles
END
close tb_Tmp
DEALLOCATE tb_Tmp
--删除临时表
if object_id('tempdb.dbo.#tb')is not null    
begin
drop table #tb
end
--建立临时表

CREATE TABLE #tb(
[Id] INT,

Prize decimal(32,2),

ProName Nvarchar(127)

)
if @@error<>0
begin
 rollback tran
 return -1
end

posted @ 2007-07-06 11:56  天纯蓝  阅读(1435)  评论(0编辑  收藏  举报