Wednesday, 24 October 2012

Copy a table from one database to another database

Copy a table from one database to another database in another ms sql server using ..

Copy a table from one database to another database in another ms sql server using sql server management studio :
If your table was in the same ms sql server but in another database, you would copy it using t-sql like this :

SELECT * INTO NewTable FROM existingdb.dbo.existingtable

SELECT * INTO NewTable FROM Sarma.dbo.DimAccount

However, if your database is in another ms sql server, you can do this :
Connect to your database using management studio. Right click on your table and select Script Table As > Create To > New Query Editor Window
Connect to the other database you want the table to be copied, create a new query and paste the sql previously generated. Run the query and you are done!


SELECT *
INTO TargetDatabase.dbo.MyTable
FROM SourceDatabase.dbo.MyTable


No comments:

Post a Comment