Reputation: 791
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
Reputation: 201
insert into dbo.FolderStatus
(
[FolderStatusId],
[code],
[title],
[last_modified]
)
select
[code],
[code],
[title],
[last_modified]
from dbo.f_file_stat
Upvotes: 0
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
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
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
Reputation: 180867
If the tables have the same columns and types, just do;
INSERT INTO table2 SELECT * FROM table1;
Demo here.
Upvotes: 4