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. :(