Click here to Skip to main content
14,834,673 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how do i copy and insert same table to different databases(one db to another db)
Posted

If they are both on the same machine then:

SQL
select *
into db2.dbo.table1
from db1.dbo.table1


This will create table1 if it does not already exist.

It will not set up the primary key, identity column, foreign keys or constraints. You will have to alter the table after the insert
   
You can make it by running SQL Server Import and Export Wizard .

You can export / import the whole DB as well as only some selected tables, take a look.
   
select *
into TargetDB.dbo.TargetTable
from SourceDB.dbo.SourceTable

Will create an new Table in TargetDB and copy the data from SourceTable.

If the TargetTable allready exists use:

insert into TargetDB.dbo.TargetTable (Column1,Column1,...)
select Column1,Column1,...
from SourceDB.dbo.SourceTable
   

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