:::: MENU ::::

Copy or move table from one Database to another

dbDigger, T-SQL Tips and Tricks

Copy or move table from one Database to another

Suppose we have a table Tab1 in database DB1. And it is required to move the Tab1 to another database DB2. So it is assumed that DB2 already exists with no or some tables in it. First of all use following T-SQL command to copy table in to destination database with all data in it.

 
SELECT *  
 INTO DB2..Tab1  
 FROM DB1..Tab1  
 GO  

Now if you have to just copy the table then its over but if you are required to move the table then use following command to drop the table from source database.

 
DROP TABLE DB1.Tab1  
 GO  

As you can see that it is done by select statement, so no affiliated objects like triggers, views etc will be copied.

  • Anonymous

    I would like to add that if you just want to copy structure of a table without any row. Then you may add the where clause like
    where 1= 2

  • Atif Shehzad

    Thanks for pointing this additional use. Its great.

Consult us to explore the Databases. Contact us