Removing an existing temporary table from ms SQL Server

Source: Internet
Author: User

Ms SQL Server has two types of local temporary tables and global temporary tables: local temporary tables are only visible in the current session, starting with a symbol # (such as # tablename ); the global temporary table is visible in all sessions and starts with a symbol # (for example, # tablename ).

SQL Server automatically adds a digital suffix to the table name of each local temporary table to distinguish temporary tables created by different users with the same name, the created temporary table will appear in the User table of the tempdb database, while the metadata is stored in the sysobjects table of the tempdb database (the name consists of the specified table name and the digital suffix generated by the system, the specified table name cannot exceed 116 characters ).

Ms SQL server automatically deletes the local temporary table when the user instance is disconnected and automatically deletes the global temporary table when all users that reference the global temporary table are disconnected.Of course, you can also explicitly call the drop TABLE statement to delete a temporary table. The statement to delete an existing temporary table is as follows:If object_id ('tempdb .. # tmp_tbl_name ') is not null drop table # tmp_tbl_name

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.