A temporary table is different from a general table. It is saved to a tempdb table. The temporary table name is different from the table name you created, because it creates different temporary tables for the same operation of different people.
1. Incorrect delete operation: -- Incorrect temporary table deletion operation because the database is different
If Exists ( Select * From Sysobjects Where Object_id = Object_id (N ' [DBO]. [# temptable] ' ) And Type In (N ' U ' ))
Begin
Drop Table [ DBO ] . [ Temptable ]
End
-- Incorrect temporary table deletion operation because the temporary table name has changed
If Exists ( Select * From Tempdb. DBO. sysobjects Where ID = Object_id (N ' [# Temptable] ' ))
Begin
Drop Table # Temptable
End
2. Correct deletion method: -- Correct temporary table deletion operation
If Object_id ( ' Tempdb .. # temptable ' ) Is Not Null Begin
Drop Table # Temptable
End