Using SQL server 2016 I have created the table VISIT with 3 columns ID,settoday,counter. This is the asp code that I use to count the daily visits. There are more than 2000 records in this table so far:
<%
'today is calculated on local calendar then:
sql="select * from visit where settoday='"& today &"'"
recordSet.open sql,objcon
if not recordSet.eof then
sql="update visit set counter=counter+1 where id=" & recordSet("id")
objcon.execute sql
else
sql="insert into visit (settoday,counter) values ('" & today & "','1')"
objcon.execute sql
end if
recordSet.close
%>
The ID column is primary key and also I have created an Index on settoday 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?