create table tablea ( tid int , mid int ) go create table tableb ( fid int, tid int ) go begin declare @coun int set @coun=1 while @coun<20 begin insert into tablea values(20,@coun) insert into tableb values(@coun,@coun) set @coun=@coun+1 end end go update tablea set tablea.tid=tableb.fid from tableb where tablea.mid=tableb.tid go