Insert values from another Table in sql server 200

2019-08-14 22:23发布

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..?

6条回答
Summer. ? 凉城
2楼-- · 2019-08-14 22:25
create table2 

insert into table2
select * from table1
查看更多
Summer. ? 凉城
3楼-- · 2019-08-14 22:34

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

INSERT INTO table2 SELECT * FROM table1;

Demo here.

查看更多
Fickle 薄情
4楼-- · 2019-08-14 22:42
insert into dbo.FolderStatus
(  
   [FolderStatusId],
   [code],
   [title],
   [last_modified]
)
select
[code],
[code],
[title],
[last_modified]
from dbo.f_file_stat
查看更多
Melony?
5楼-- · 2019-08-14 22:43

use following stcript:

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

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

查看更多
女痞
6楼-- · 2019-08-14 22:44

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
查看更多
戒情不戒烟
7楼-- · 2019-08-14 22:46

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) 
查看更多
登录 后发表回答