title: System.OutOfMemoryException when querying large SQL table
body: <p>I've written a SQL query that looks like this:</p>
  
  <pre><code>SELECT * FROM MY_TABLE WHERE ID=123456789;
  </code></pre>
  
  <p>When I run it in the Query Analyzer in SQL Server Management Studio, the query never returns; instead, after about ten minutes, I get the following error: <code>System.OutOfMemoryException</code></p>
  
  <p>My server is Microsoft SQL Server (not sure what version).</p>
  
  <pre><code>SELECT * FROM MY_TABLE; -- return 44258086
  SELECT * FROM MY_TABLE WHERE ID=123456789; -- return 5
  </code></pre>
  
  <p>The table has over forty million rows!  However, I need to fetch five specific rows!</p>
  
  <p>How can I work around this frustrating error?</p>
  
  <p><b>Edit:</b> The server suddenly started working fine for no discernable reason, but I'll leave this question open for anyone who wants to suggest troubleshooting steps for anyone else with this problem.</p>