SQL Server Temp Table

Source: Internet
Author: User

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

For example, it is clearer to look at the local temporary table, "New query", enter the following text:


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

We also open a "new query", named it as a new query 2, in the new query 2 to execute the input: SELECT * from #tempTable, prompt as follows:

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

Note that after you use the global temporary table, do not forget to drop table out of it. However, with local temporary tables, you can do this without doing this, and the local temporary tables created are automatically reclaimed at the end of the current session.

For detailed usage please refer to: http://www.cnblogs.com/shineqiujuan/archive/2008/11/13/1332657.html

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.