Mssql temporary table creation code

Source: Internet
Author: User
Tags mssql server
Mssql temporary table creation code ifobject_id (tempdb. dbo. # table) isnotnull & nbsp; droptable # tablegocreatetable # table ([field] type) the code above checks whether a temporary table exists # If it exists, delete it, otherwise, the temporary table is created. * Code for creating a temporary table in mssql for mssqlserver temporary tables

If object_id ('tempdb. dbo. # table') is not null
Drop table # table
Go
Create table # table ([field] type)

// The code above is used to determine whether the temporary table # table exists. If yes, delete the table; otherwise, create the temporary table.

/*
Mssql server temporary table related operations

Create temporary table
Method 1:

Create table # temporary table name (Field 1 constraints,
Field 2 constraints,
.....)
Create table # temporary table name (Field 1 constraints,
Field 2 constraints,
.....)

Method 2:

Select * into # temporary table name from your table;
Select * into # temporary table name from your table;
Note: The above # indicates a local temporary table, and # indicates a global temporary table.

Query temporary tables
Select * from # temporary table name;
Select * from # temporary table name;

Delete temporary table
Drop table # temporary table name;
Drop table # temporary table 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.