SQL Server - Difference between Insert and Update
Asked By Basavaraj on 08-Dec-10 07:10 AM
I have thousands of records in few tables. I have written a stored procedure to retrieve and update records in my table,
I have 7 UPDATE statements in my Stored procedure. Would using 7 UPDATE statements hit the performance?
Is there any alternate>?
Sagar P replied to Basavaraj on 08-Dec-10 07:26 AM
Actually performace depends on the total number of records of table and WHERE clause of UPDATE statement.
So check this link which will tell you some hints for improving performance in case of update;
http://searchoracle.techtarget.com/answer/Improve-performance-of-SQL-query
http://www.tek-tips.com/faqs.cfm?fid=767
Ramendra Kumar replied to Basavaraj on 08-Dec-10 08:01 AM
if u think ur job can do with case then i will say to use case
Basavaraj replied to Sagar P on 08-Dec-10 08:02 AM
Currently i am testing the query with 10 records. But the query actually has to run in an environment where there will 7Lacs + records
sri sri replied to Basavaraj on 08-Dec-10 11:01 AM
hi,
in order to increase the performance, add index in your tables with the fields often used in the 'where' condition
u r updating the same table by using the 7 query?
then u can write a single update query.
check the below query for example
update myTable set field1='value1' , field2='value2' where id = 10
Basavaraj replied to sri sri on 08-Dec-10 11:33 PM
sri sri replied to Basavaraj on 09-Dec-10 10:57 AM