There are several ways to make a SQL copy table, and here's a summary for easy use
SELECT * into target table name from source table name INSERT into target table name (Fld1, fld2) Select Fld1, 5 from source table name |
The first target table does not exist, creates a new table, but copies the data, but does not copy information such as indexes
The second Table destination table is present, you can specify that the column is copied from the source table and you can specify the related column
Commonly used for both of these uses, the following is taken from the network
copy table structure and data SQL statements
1: Copy table structure and data to a new table
SELECT * into destination database name. dbo. destination table name from the original table name
SELECT * Into My0735home.dbo.infoMianTest from Infomian
2: Back up part of the table column (do not write * and write out the list of columns)
Select Column Name 1, column name 2, column name 3 into destination database name. dbo. destination table name from the original table name
Select Id,title,mtype,stype,author,tel,nr to InfoMianTest2 from Infomian
3: Part of the backup table row (plus where condition)
SELECT * into destination database name. dbo. destination table name from the original table name where id<10
SELECT * into Infomiantest2 from Infomian where id<10
4: Back up part of a table column (do not write * and write out a list of columns) and a subset of rows (plus where condition)
Select Column Name 1, column name 2, column name 3 into destination database name. dbo. destination table name from the original table name where id<10
5: Copy only the structure of the table: for example: SELECT * Inot T1 from titles WHERE 1=2
6: Query results from multiple tables:
SELECT Title_id,title,pub_name into T3
From titles T INNER JOIN Publishers P
On t.pub_id=p.pub_id
Transferred from: http://liujiassd.blog.163.com/blog/static/8311714320094283334854/