现在的位置: 首页 > 综合 > 正文

SQL遍历所有表建立临时表

2013年06月12日 ⁄ 综合 ⁄ 共 566字 ⁄ 字号 评论关闭

--遍历所有表
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

抱歉!评论已关闭.