I have a simple sql call like :-
select col1,col2 from table1
and sometimes the system runs the following:-
update table1
set col3 = 'something'
where col1 ='s1' and col2 ='s2'
These queries are ran through various applications running on our server and it only happens on one table which has something like 100k rows.
I have tables with millions of rows – it doesn’t timeout on them but not sure why it does on this one.
These queries run all day long without any problems but sometimes during the day – specially during peak times – they fail with error – timeout expired –
Can you please tell me what things can I try to resolve this error
Do I need to perform some type of locking ?
Also is it true that if a user is updating a comment and then other user on the system tries to update the same row in the table – will it timeout the 2nd user because the row is locked for editing – is there a way around that?
I have found the answer –
Because it was a table in the old system – the previous users didn’t add a primary key thinking that there is already a virtual primary key in there but it wasn’t right.
As the sql would take too long for editing and would timeout.
So I just made a composite key in the table and now it is working alright.
Conclusion – Never have a table without a primary key if you are going to be dealing with updating,deleting data
Thanks everyone for your comments