Link to home
Start Free TrialLog in
Avatar of Marcus Aurelius
Marcus AureliusFlag for United States of America

asked on

Most Optimized Way to Update a Table using STORED PROCEDURE?

Experts,

Which is the most optimized way to update a table using a STORED PROCEDURE?


Like this?:
----------
update a
set col1 = b.col1
from table1 a
inner join --SUBQUERY TABLE
      (select id, desc
            from table3) b on a.id = b.id




OR like this:
-------------
create table #Temp1 (id int, desc varchar(25))
insert into #Temp1
(select id, desc
      from table3)

update a
set col1 = b.col1
from table1 a
inner join #Temp1 b on a.id = b.id
SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marcus Aurelius

ASKER

Assume Indexed on Col1 "ID".

I'm seeking more of a "generally speaking" type of feedback.

Is it generally speaking better to have the stored procedure process the update using a "SUB-QUERY" as an inline table...

OR

Use the query to load a TEMP TABLE and use the TEMP TABLE to link to in an UPDATE STATEMENT.....?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for all the input