Reputation: 399
I have a temporary table in the stored procedure which is causing the time out for the query as it is doing a complex calculation. I want to drop it after it is used. It was created like
DECLARE @SecondTable TABLE
Now I cannot drop it using
drop @SecondTable
in fact I have to use
drop #SecondTable
Does somebody know why?
Upvotes: 0
Views: 1193
Reputation: 8574
I'm by no means a SQL guru, but why is the drop even necessary?
If it's a table variable, it will no longer exist once the stored proc exits.
I'm actually surprised that DROP #SecondTable
doesn't error out on you; since you're dropping a temporary table there; not a table variable.
EDIT
So based on your comment, my updates are below:
1.) If you're using a table variable (@SecondTable
); then no drop is necessary. SQL Server will take care of this for you.
2.) It sounds like your timeout is caused by the calculations using the table, not the dropping of the table itself. In this case; I'd probably recommend using a temporary table instead of a table variable; since a temporary table will let you add indexes and such to improve performance; while a table variable will not. If this still isn't sufficient; you might need to increase the timeout duration on the query.
3.) In SQL; a table variable (@SecondTable
) and temporary table (#SecondTable
) are two completely different things. I'd refer to the MSDN documentation for Table Variables and Temporary Tables
Upvotes: 3