1. Incorrect deletion operation: -- The temporary table deletion operation is incorrect, because different IFEXISTS (SELECT * FROMsysobjectsWHEREobject_idOBJECT_ID (N [dbo]. [# tempTable]) ANDtypein (NU) BeginDROPTABLE [dbo]. [tempTable] End -- the temporary table deletion operation is incorrect because
1. Incorrect deletion operation: -- The temporary table deletion operation is incorrect because the database WHERE the table is located is different from if exists (SELECT * FROM sysobjects WHERE object_id = OBJECT_ID (n' [dbo]. [# tempTable] ') AND type in (n'u') Begin drop table [dbo]. [tempTable] End -- the temporary table deletion operation is incorrect because
1. Incorrect delete operation:
-- The temporary table deletion operation is incorrect 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
-- The temporary table deletion operation is incorrect 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