Insert values from another Table in sql server 200

2019-08-14 21:57发布

问题:

I have to copy all column data to another table.I have created a new blank table.How to insert the values in it.I am avoiding writing the column name manually because it contain 35 column name in it.Sequence & name of column are same in both the table..?

回答1:

If the tables have the same columns and types, just do;

INSERT INTO table2 SELECT * FROM table1;

Demo here.



回答2:

use following stcript:

INSERT INTO "table1" ("column1", "column2", ...)
       SELECT "column3", "column4", ...
          FROM "table2"

for more information see: http://www.1keydata.com/sql/sqlinsert.html



回答3:

Create table2 with columns and datatype for each column. If the columns match up exactly on both tables, then insert into table2 from table1

Create table table2(
column1 datatype, 
column2 datatype,
column3 datatype,
column35 datatype
}

INSERT INTO table2
SELECT * from table1


回答4:

create table2 

insert into table2
select * from table1


回答5:

Please find my verion . i had same column name in both tables

    INSERT INTO first_table 
            (column_1, 
             column_2, 
             column_3, 
             column_etc)

SELECT tab2.column_1 AS column_1, 
       10            AS column_2, 
       Getdate()     AS column_3, 
       'some_text'   AS column_etc

FROM   second_table tab2 (nolock) 


回答6:

insert into dbo.FolderStatus
(  
   [FolderStatusId],
   [code],
   [title],
   [last_modified]
)
select
[code],
[code],
[title],
[last_modified]
from dbo.f_file_stat