SQL Server temporary table Deletion

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.