November 5, 2007 at 6:48 am
Hi Experts,
Explain me the difference between Worktable and temptable ? I need dame good technical answers for this question.
Inputs are Welcome !
karthik
November 5, 2007 at 2:58 pm
A Worktable is a temporary table used internally by SQL Server, typically for sorting or for cursor results.
A TempTable is a temporary table defined by a user.
SQL = Scarcely Qualifies as a Language
November 5, 2007 at 3:20 pm
Keep in mind that while Carl's answers are correct, both terms are used in ambiguous manners quite frequently in the SQL world, especially "work table".
I've seen people refer to tables that are created and dropped inside of a stored proc, for example, as work tables. What they're doing is using them as quasi-temp-tables (but by commenting out the drop statement they live outside the scope of the session for debugging, for instance), and I've even seen them to referred to as temp tables, as well.
November 5, 2007 at 10:36 pm
I agree with David although Carl is spot on technically... lot's of folks think of a "work table" as a sort of permanent temp table where no damage will be done if the contents of the table are truncated. In our standards at work, we even require that such tables be prefixed with "wt" to identify their expendible nature.
Why use such a thing? Sometimes you need a scratchpad like a Temp table, but on extremely large batch runs, such a table would quickly overwhelm TempDB if a temp table were used. Solution... make the batch job so only one instance can execute at a time (we use a token log for that) and make a "work table".
--Jeff Moden
Change is inevitable... Change for the better is not.
November 5, 2007 at 10:40 pm
Also, to help you with the "dame good technical answers" for the "dame" good interview, test, or homework question ;), you really should turn to Books Online. A simple lookup of "worktable" will give you a "dame" good technical answer 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
November 6, 2007 at 2:50 am
I agreed all your experts answer. But in memory level where worktable will be stored ?
For example if i create # table then it will be stored in TempDatabase.
But if use groupby,orderby etc., then it will create worktable. I agreed it is an internal process which is handled by sqlserver. My question is where exactly worktables will be stored ?
karthik
November 6, 2007 at 8:18 am
Using David and Jeff's definition - a work table is a table used for temporary purposes. You could create it anywhere: in the local database, in tempDB, some other database. Temp tables are in tempdb under that definition. (I also tend to use this verbiage, albeit technically wrong).
Using the "correct" technical definition - work tables are created in tempDB, temp tables, anywhere.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
November 6, 2007 at 8:35 am
karthikeyan (11/6/2007)
I agreed all your experts answer. But in memory level where worktable will be stored ?For example if i create # table then it will be stored in TempDatabase.
But if use groupby,orderby etc., then it will create worktable. I agreed it is an internal process which is handled by sqlserver. My question is where exactly worktables will be stored ?
Work Tables that are spawned by the system are as if they were TempTables... that is, if they fit in memory, they will live in memory as Temp Tables do (under the guise of TempDB)... if they don't fit in memory, they will spool off into the TempDB disk space.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 6, 2007 at 12:00 pm
From "Alice in Wonderland"
Humpty Dumpty: When I use a word, it means just what I choose it to mean - neither more nor less.
Alice: The question is, whether you can make words mean so many different things.
Humpty Dumpty: The question is: which is to be master - that's all.
SQL = Scarcely Qualifies as a Language
November 6, 2007 at 12:35 pm
more info about worktables
🙂
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarsqlsg/html/msdn_showplan.asp
November 7, 2007 at 12:43 am
Thanks Jeff and Matt !:) Now I am very clear about WrokTable and TempTable 😎
karthik
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply