Copying tables between databases on SQL Server

Copying tables from one database to another is pretty straight foward. No need to create the destination table as the script will create it on the fly.

Assume a database called sourceDB and a database called destinationDB (all owned by dbo for this example). To duplicate the table called myTable the syntax would be.

USE destinationDB

SELECT * INTO destinationTable FROM sourceDB.dbo.myTable

That’s it .. a copy now exists in the destinationDB. One thing you will need to you is establish the primary key on the copy as it is not created as part of the copy.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s