Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 UPDATE vs. multiple temp tables

Author  Topic 

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-05-11 : 16:45:28
So I learned (the hard way) that it's a lot faster to do things in steps with temporary tables rather than one giant query when you've got big tables and lots of joins involved. But let's say I'm building a new table a couple of columns at a time - would it be better to do it with temp tables (let's say it'll take at least a few and they each have over a million records) or build the permanent table with NULLs and UPDATE it with each step? Or UPDATE a temp table and dump it into a permanent table at the end?

Sorry I don't have a concrete example; this was just another thing I was curious about (I just recently read about UPDATE). Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-11 : 16:52:39
There is no direct answer for your question. It really just "it depends". We would need a concrete example to work out the details.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2011-05-11 : 19:29:30
Like Tara said - it depends. Creating a table and inserting a million rows, then running multiple updates across that table would likely take longer than just inserting the million rows with the right values up front.

It really does depend on how each columns values are derived.

Jeff
Go to Top of Page
   

- Advertisement -