Original article: http://www.cnblogs.com/kwklover/archive/2007/11/23/969633.html
Problem summary: Check whether the ms SQL Server temporary table exists
Drop table # tempcitys
Select * into # tempcitys from hy_citys
When the preceding statement is run for the first time, it must have encountered an error, but it will not be used for the second time.
Because select * into # tempcitys from hy_citys automatically creates a temporary table # tempcitys, the first temporary table does not exist, and a drop table error occurs naturally.
At the beginning, no response was made. Select * into will automatically create a temporary table.
Therefore, it is more reliable to determine whether a temporary table exists and then drop the table
If exists (select * From tempdb. DBO. sysobjects where id = object_id (N 'tempdb .. # tempcitys ') and type = 'U ')
Drop table # tempcitys
Note that tempdb is followed by two. Not one
Consider writing another SQL statement
Insert into # tempcitys (cityid) Select cityid from hy_citys
In this way, # tempcitys will not be automatically created. To use # tempcitys, you must first create table # tempcitys (cityid INT)
I am confused. The result of poor learning skills. :(