SQL replication tables, copy tables, temporary tables

Source: Internet
Author: User

--insert into pppcopy SELECT * FROM PPP//Get data from table PPP and insert it into pppcopy, copy only table data, do not copy table structure (prerequisite: Table pppcopy1 exists)


--select * into PPPCOPY1 from PPP//copy data from PPP to PPPCOPY1, copy table data and table structure (provided that table pppcopy1 does not exist)

--select * into PppCopy2 from PPP where 1=0//copies the table structure of PPP to PPPCOPY2, without copying data (provided that table pppcopy1 does not exist)

--create table #temp (num int primary key,pname varchar (20))//create local temporary table

--create table # #temp (num int primary key,pname varchar (20))//Create global temporary table, delete when SQL service disconnects

Local temporal tables differ from global temporary tables and examples

1, the Local temporary table (#开头) is only valid for the current connection, and is automatically deleted when the current connection is broken.
2, the Global temporary table (# #开头) is also valid for other connections and is automatically deleted when the current connection and other connections that have accessed it are disconnected.
3, whether the local temporary table or the global temporary table, as long as the connection has access rights, you can use the drop table #Tmp (or drop table # #Tmp) to explicitly delete the temporary table.

SQL replication tables, copy tables, temporary tables

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.