#me { float: left; }

November 18, 2009

Copying tables between databases on SQL Server

Filed under: SQL Server — Simon Rigby @ 3:43 pm

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.

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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 )

Connecting to %s

Theme: WordPress Classic. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.