Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi to all,
How to insert data from one database table to another database table.
for example:
In db1 :-i have some country table and column is id,name
in db2 :-i have some country table and column in id,name
id is autogenerate value

how to insert db2 data to db1.

above example just for our understanding but my table contain 15 column so how to do that and have one column as autogenerate key

What I have tried:

i need example code how to do.
Posted
Updated 22-Feb-16 0:14am

1 solution

SQL
insert into db1.dbo.country (columnA, ColumnB)
Select columnA, columnB from db2.dbo.country
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 22-Feb-16 6:23am    
if have two fields its ok but my table have 25 fields how to do and i have identity key that means primary key . how can i do
Jawad Ahmed Tanoli 22-Feb-16 6:30am    
autogenerate key is in both tables ? you want to keep the db2 country table same id in db1 country table or not ?
JOTHI KUMAR Member 10918227 22-Feb-16 6:36am    
Actually both database have same table and fields. i need to merge record bcz last month is in one database and this month is in one database so i need to merge two month in one database that means either db1 or db2 that all
Jawad Ahmed Tanoli 22-Feb-16 6:43am    
insert into db1.dbo.country
Do not include auto generate column if you want your table to create it for your self
Select ColumnB,ColumnC,,,,,,,,,,,, from db2.dbo.country
Member 13671635 26-Apr-18 7:31am    
I have large data of amount have a million records its takes more time in execution please tell me how its fast

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900