manoj kumar singh
manoj kumar singh

Reputation: 791

Insert values from another Table in sql server 2008

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

Upvotes: 1

Views: 22470

Answers (6)

Lokanathan
Lokanathan

Reputation: 201

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

Upvotes: 0

Abhi
Abhi

Reputation: 6568

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) 

Upvotes: 0

Satinder singh
Satinder singh

Reputation: 10198

create table2 

insert into table2
select * from table1

Upvotes: 0

Patriotec
Patriotec

Reputation: 1144

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

Upvotes: 0

Sam
Sam

Reputation: 6890

use following stcript:

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

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

Upvotes: 2

Joachim Isaksson
Joachim Isaksson

Reputation: 180867

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

INSERT INTO table2 SELECT * FROM table1;

Demo here.

Upvotes: 4

Related Questions