Quantcast
Channel: beyondrelational.com
Viewing all articles
Browse latest Browse all 25

SQL Server does not allow to create a TEMP table twice in the same batch, even after you drop the first table.

$
0
0
In SQL Server, a temporary table with the same name could not be re-created in the same batch, even if you drop and re-create. The following script clarifies the concept. Try by self CREATE PROCEDURE TempTabTest AS BEGIN -- first set of data if object_id ( 'tempdb..#temptab') is not null drop table #temptab; create table #temptab( n1 int, n2 int); -- some code -- second set of data if object_id ('tempdb..#temptab') is not null drop table #temptab; create table #temptab( n1 int, n2 int); -- some code END You will get an error message "There is already an object named '#temptab' in the database.". If you are using a permanent table instead of temporary table, it would get compiled. This is a feature by design.

Viewing all articles
Browse latest Browse all 25

Trending Articles