I have the below stored procedure that is taking close to an hour to complete. The result set is about 200K machines.
All I am doing is extracting a set of ids from a remote server,delete those ids in local server and then extract all details for those ids from remote server and insert it. The INSERT takes 90%, DELETE table 9% and SELECT INTO 1%.
id is primary key/clustered index.
DECLARE @ProcessDate DATETIME SET @ProcessDate = CONVERT(VARCHAR(10), DATEADD(DAY, -3, GETDATE()), 111) SELECT DISTINCT id INTO #temp_machines FROM table1 WHERE dt_modify >= @ProcessDate DELETE FROM table2 WHERE id IN ( SELECT id FROM #temp_machines ) INSERT INTO table2 SELECT * FROM table1 WHERE id IN ( SELECT id FROM #temp_machines )
Any suggestions on improving performance?