SQL Modify table structure, temp table application

Source: Internet
Author: User

ALTER TABLE dbo. P_zpromotion_doc_items_temp ALTER COLUMN Mcrank varchar (20);

Method One: Use TestDB

--Creating a local temporary table create table #tmpStudent (Tid int,name varchar (), age int)

INSERT into #tmpStudent values (' Xiaowang ', 25)

SELECT * FROM #tmpStudent

--Create a local temporary table another way of writing select * into #tmpStudent from student

SELECT * FROM #tmpStudent

Method Two: Create table tempdb. mytemptable (Tid int)--You can write this with a corresponding permission

Delete tables: Drop table #tmpStudent

SQL temporary table usage Summary 1, creation Method: Method One: Create table temptablename or select [Field 1, Field 2,...,] into Temptablename from table method two: Create Tabl e tempdb. mytemptable (Tid int) Description: (1), the temporary table is actually placed in the database tempdb in a user table, (2), temptablename must have "#", "#" can be one or two, with # (local) or # # (global) Start of the table, This kind of table exists during the session, and the session end is deleted automatically; (3), if created without the # or # #开头, and tempdb. TempTable to name it, the table can persist until the database is restarted. 2. Manually delete the drop table Temptablename Description: The drop TABLE statement explicitly drops the temporary table, otherwise the temporary table will be automatically dropped by the system when it exits its scope: (1), when the stored procedure completes, the local temporary table created in the stored procedure is automatically dropped. This table can be referenced by all nested stored procedures that are executed by the stored procedure that created the table. However, the process calling the stored procedure that created this table cannot refer to this table, (2), all other local temporary tables are automatically dropped at the end of the current session, and (3) the global temporary table is automatically dropped when the session that created the table ends and other tasks stop referencing them. The association between a task and a table is persisted only within the lifetime of a single Transact-SQL statement. In other words, when the session that created the global temporary table ends, the last Transact-SQL statement referencing this table is finished and the table is automatically dropped.

SQL Modify table structure, temp table application

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.