Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Should I use temp tables or derived tables?
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00716200
Message ID:
00716370
Views:
14
>If I can write my stored procedure using derived tables instead of temp tables, should I do so? Or are temp tables o.k. if I want to keep my stored procs easy to read?

Use derived tables when you can. If you can't, use a Table variable (SQL Server 2000) before using an actual temporary table.

>Also, what are the pitfalls of using temp tables over derived tables?

Temp tables require a little more work on your part and on the part of SQL Server. Many times, the derived table and be imbedded in the query plan. There are also locking requirements as the table is created in tempdb.

Table variables behave like temporary tables but are created in memory.

Of course, depending on what you query is doing and the amount of data that your affecting, SQL Server can always decide that it needs a work table and create it in tempdb.

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Reply
Map
View

Click here to load this message in the networking platform