Groups | Blog | Home
all groups > sql server mseq > september 2003 >

sql server mseq : Copying Data from one table to another


Wes
9/11/2003 2:06:01 AM
I have 2 database tables with the same number of columns.
Using SQL, I want to transfer all the data from one table
to another. The columns are named differently in each
table but the order of the columns is correct.

Here's an example ...

Table 1
CUST_NAME CUST_ADDR CUST_TYPE
Joe Bloggs New York Business
Steve Mahl Chicago Resiendtial

Table 2
COL1 COL2 COL3
Pete Evans Miami Residential
Steve Cooper Texas Business

I would like a command to transfer all data from Table 2
to Table 1

Thanks for your help,
Vishal Parkar
9/11/2003 5:16:46 AM
use syntax INSERT INTO...SELECT
Ex:
in your case the statement syntax would be as follows.:

insert into <dest_db>.owner.table1(cust_name,cust_addr, cust_type)
select col1,col2,col3 from <source_db>.owner.table2

Make sure you have required privileged in the database and use 3 part naming
convention. I hope you are transferring table data on the same server. If
not then you will have to use linked server and use 4 part naming
convention.

--
-Vishal

[quoted text, click to view]

Wes
9/12/2003 2:15:47 AM
Thanks Vishal,

the databases were both on the same server.
AddThis Social Bookmark Button