September 14, 2012 at 1:16 am
Is it good to use Temporary Tables in the Stored procedure or is it better to use actual tables instead of Temp tables????
************************************
Every Dog has a Tail !!!!! :-D
September 14, 2012 at 6:10 am
Depends what you need.
#Temporary tables can only be accessed by the instance of stored procedure that is running. If two instances of the stored proc are running they each get their own version of the #Tmp table.
If you create dbo.Tmp in tempdb - there is only one tempdb.dbo.Tmp table - your stored proc will have to check if it exists, if not create it, and deal with all the issues of possibly sharing the table with other instances of the proc.
But if you want the data to be available outside the proc, just use a real table in the database, because tempdb is recreated when the server restarts, and it is not backed up.
September 14, 2012 at 7:39 am
Do #tables cause stored procedure recompilation???
September 14, 2012 at 7:43 am
Creating and dropping temporary tables forces a recompile.
September 14, 2012 at 7:47 am
Partial recompile.
Statement-level, not proc-level.
Example here: http://sqlserverplanet.com/sql-optimization/temp-table-recompiles/
Excellent article on table variables and temp tables and other options: http://www.simple-talk.com/sql/t-sql-programming/temporary-tables-in-sql-server/
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
September 14, 2012 at 8:20 am
GSquared (9/14/2012)
Partial recompile.Statement-level, not proc-level.
Example here: http://sqlserverplanet.com/sql-optimization/temp-table-recompiles/
Excellent article on table variables and temp tables and other options: http://www.simple-talk.com/sql/t-sql-programming/temporary-tables-in-sql-server/
Thanks: very useful information. 🙂
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply