0

We work with tables with a lot of records. Anyone knows if is better to make a Count(*) or a Top 1 to know if a specific record exists or a group of records match some conditions. Also this type of sentence lock the table or I need to specify no lock the table.

  • If you don't actually need the count, and there is no sorting involved, a TOP 1 of just the row id should be fastest. A count can take time. – Thilo Jun 24 '14 at 09:10

1 Answers1

0

If you don't care about the possibility of dirty reads you can try this

   SELECT TOP(1)
       FROM YourTable WITH (NOLOCK)
    WHERE ..... (your conditions here)
g2server
  • 5,037
  • 3
  • 29
  • 40