Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need advice re: best practices with Table variables 3

Status
Not open for further replies.

Sheco

Programmer
Jan 3, 2005
5,457
US
When I create a temp table inside a stored procedure, it is my habbit to explictly drop it when I'm done... rather than just letting it go out of scope.

Is there anything like this I should be doing to table variables?
 
DROP TABLE @blah?

Mission impossible :)

------
[small]<this is sig>
select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')
</this is sig>[/small]
[banghead]
 
Is it a good idea for any reason other than consistancy with the way the temp tables are done?
 
pffffttt.

[tt][red]Server: Msg 170, Level 15, State 1, Procedure spV2_ClientSearch_New, Line 343[/red]
Line 343: Incorrect syntax near '@ResultSet'.[/tt]
 
Is there anything like this I should be doing to table variables?

No.

You can't drop a table variable. Just let it go out of scope.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Since @variables cannot be dropped or set to Empty or Nothing or TRUNCATEd... the only eventual option is DELETE FROM.

------
[small]<this is sig>
select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')
</this is sig>[/small]
[banghead]
 
Is there anything to be gained by explicitly deleting?
 
Here is one hypothetical scenario:
Code:
create proc someproc
as

	declare @table table (... )
	
	insert into @table
		<several million rows>
		
	-- some calculations on @table
	
	-- from this point @table is no more necessary
	
	-- other pieces of sproc taking long time to finish
go
In other words: very likely - not.

------
[small]<this is sig>
select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')
</this is sig>[/small]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top