Brief analysis of SQL Server temporary table _mssql

Source: Internet
Author: User

Create a temporary table, #代表局部临时表, # #代表全局临时表. What is the specific meaning of a local temporary table and a global temporary table?

For example, the more clear, first look at the local temporary table, "New query", enter the following text inside:


After running, we execute the input in this file: SELECT * from #tempTable, after execution can query the following data:

We opened a new query and named it new Query 2, which is executed in new query 2: SELECT * from #tempTable, which prompts you as follows:

To modify the #temptable in the SQL statement to # #tempTable, execute again according to the above method, you will find that new query 2 no longer prompts for errors, can detect and new query 1 in the same results. Why?=> Local temporary tables are visible only in the current session, and global temporary tables are visible in all sessions.

Note that when you use a global temporary table, do not forget to drop table to drop it. However, you can use local temporary tables without doing so, and the local temporary tables that you create are automatically recycled at the end of the current session.

Temporary table specific usage please refer to http://www.jb51.net/article/23952.htm

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.