在 sql server 2008 中插入另一个表中的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9600774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:42:43  来源:igfitidea点击:

Insert values from another Table in sql server 2008

sqlsql-server-2008

提问by manoj kumar singh

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

我必须将所有列数据复制到另一个表。我创建了一个新的空白表。如何在其中插入值。我避免手动编写列名,因为它包含 35 个列名。列的序列和名称是两个表都一样..?

回答by Joachim Isaksson

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

如果表具有相同的列和类型,就这样做;

INSERT INTO table2 SELECT * FROM table1;

Demo here.

演示在这里

回答by Sam

use following stcript:

使用以下脚本:

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

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

有关更多信息,请参阅:http: //www.1keydata.com/sql/sqlinsert.html

回答by Satinder singh

create table2 

insert into table2
select * from table1

回答by Patriotec

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

使用列和每列的数据类型创建 table2。如果两个表上的列完全匹配,则从 table1 插入 table2

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

INSERT INTO table2
SELECT * from table1

回答by Abhi

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) 

回答by Lokanathan

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