title: How to optimize visit counter SQL query?
body: <p>Using SQL server 2016 I have created the table <strong>VISIT</strong> with 3 columns <strong>ID</strong>,<strong>settoday</strong>,<strong>counter</strong>. This is the <strong>asp</strong> code that I use to count the daily visits. There are more than 2000 records in this table so far:</p>
  <pre><code>&lt;%
  'today is calculated on local calendar then:
  
  sql=&quot;select * from visit where settoday='&quot;&amp; today &amp;&quot;'&quot;
  recordSet.open sql,objcon
  if not recordSet.eof then
  
      sql=&quot;update visit set counter=counter+1 where id=&quot; &amp; recordSet(&quot;id&quot;)
      objcon.execute sql
  
  else
      
      sql=&quot;insert into visit (settoday,counter) values ('&quot; &amp; today &amp; &quot;','1')&quot;
      objcon.execute sql
  
  end if
  recordSet.close
  %&gt;
  </code></pre>
  <p>The ID column is primary key and also I have created an Index on <strong>settoday</strong> column. But When I check the Event profiler, The update query is taking a long time to execute. What more can I do to optimize the update code?</p>