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
LVL 17
MIKESoftware Solutions ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
It depends on factors like if / how columns are indexed, etc.

Why don't you pull up the query plan yourself ?
0
Scott PletcherSenior DBACommented:
Because "desc" isn't being used in the query, you can remove it from the query.

Just make sure you can index keyed on id on table3.  Include the "desc" column in the index if it is actually being used in the query.
0
MIKESoftware Solutions ConsultantAuthor Commented:
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.....?
0
Scott PletcherSenior DBACommented:
Just join directly.  Loading the temp table just wastes time if there's already a covering index.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MIKESoftware Solutions ConsultantAuthor Commented:
thanks for all the input
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.