title: Temp table behavior in SQL Server 2008 R2
body: <p>I am executing below script.</p>
  
  <pre><code>declare @id int = 0
  
  while(@id &lt; 10)
  begin
      declare @tbl as table (id int)
  
      insert into @tbl values(@id)
      set @id = @id + 1
  
      SELECT * FROM @tbl
  end
  </code></pre>
  
  <p>I am getting result like below.</p>
  
  <p><a href="https://i.stack.imgur.com/GKmb5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GKmb5.png" alt="Result"></a></p>
  
  <p>but this script should give only one row every time in temp table because temp table is declaring every time in while loop and I am inserting only one value in table.</p>
  
  <p>I don't understand this behavior of temp table, please suggest.</p>