title: Select and Delete in the same transaction using TOP clause
body: <p>I have table in which the data is been continuously added at a rapid pace.</p>
  
  <p>And i need to fetch record from this table and immediately remove them so i cannot process the same record second time. And since the data is been added at a faster rate, i need to use the <code>TOP clause</code> so only small number of records go to business logic for processing at the time.</p>
  
  <p>I am using the below query to </p>
  
  <pre><code>BEGIN TRAN readrowdata
  SELECT    
   top 5 [RawDataId],    
   [RawData]    
  FROM    
   [TABLE]  with(HOLDLOCK)  
  
   WITH  q AS
      (
          SELECT    
          top 5 [RawDataId],    
          [RawData]    
          FROM    
          [TABLE]  with(HOLDLOCK)  
      )
  
  DELETE from q  
  COMMIT TRANSACTION readrowdata  
  </code></pre>
  
  <p>I am using the HOLDLOCK here, so new data cannot insert into the table while i am performing the SELECT and DELETE operation. I used it because Suppose if there are only 3 records in the table now, so the SELECT statement will get 3 records and in the same time new record gets inserted and the DELETE statement will delete 4 records. So i will loose 1 data here.</p>
  
  <p>Is the query is ok in performance term? If i can improve it then please provide me your suggestion.</p>
  
  <p>Thank you</p>