Copy tables between databases in SQL Server


There are multiple methods to copy tables between databases in SQL Server:

  • Using SQL Server Management Studio (SSMS):
  • Open SSMS and connect to the source database.
  • Right-click on the table you want to copy and select "Script Table as" -> "CREATE To" -> "New Query Editor Window".
  • This will generate a script to create the table in a new query window.
  • Change the database name in the script to the destination database and execute the script to create the table in the destination database.

  • Using SQL Server Import and Export Wizard:

  • Open SQL Server Import and Export Wizard from the Start menu.
  • Select the source database and table, and then select the destination database.
  • Choose the "Copy data from one or more tables or views" option and select the table you want to copy.
  • Follow the wizard steps to complete the copy process.

  • Using T-SQL:

  • Open a new query window and connect to the source database.
  • Use the SELECT INTO statement to create a new table in the destination database and copy the data from the source table:
     USE DestinationDatabase;
     SELECT *
     INTO NewTable
     FROM SourceDatabase.dbo.SourceTable;
  • This will create a new table called "NewTable" in the destination database and copy all the data from "SourceTable" in the source database.

Note: Make sure that the destination database has the same schema as the source database before copying the table.



About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.