Home » Blog » migration » Copy Table from One Database to Another Database in SQL Server

Copy Table from One Database to Another Database in SQL Server

author
Published By Aswin Vijayan
admin
Approved By Anuraag Singh
Published On October 4th, 2023
Reading Time 8 Minutes Reading
Category migration, SQL Server
copy sql table one database to another

With the launch of SQL Server 2022 version, users are curious about it & are eagerly trying to copy table from one database to another in the new server. However, even if it’s not about any other server, migrating SQL databases between different databases is a bit tricky. However, with proficient technical knowledge & the right technique, this isn’t that difficult.

In this blog, we are going to help users learn how to migrate data from one database to another without facing any errors or complications. Moving forward, this blog aims to offer all the possible solutions to users with step-by-step solutions for solving their queries. We are pretty sure, users can be experts at this task by the end of this informative article. Moreover, FAQs & user queries are also mentioned here for users to understand the problem and the solution in depth.

User Queries for SQL Copy Table from One Database to Another

Now, before we move toward the solution, we must go through the user queries to understand what really a user goes through for such a task. Furthermore, we must say that such queries help us understand the user intent & the point of trouble in depth.

Hi sir, I’m working in a data company for the last 2 years as a DBA. I’m aware of a few ways to migrate databases but can you help me learn all the possible ways? Moreover, automated solutions are my priority to copy table from one database to another SQL Server Database. Please suggest a reliable tool as well for the same. Thank you.

  • Frank Morales

I’m a bit worried as I want to copy table from one database to another in SQL Server. I’m working in a retail shop & handle all the database myself. I’m a bit new to this & this is why I want a firm solution for this that can help me save time.

  • Nylah Wood

Now, that we are aware of what users are searching for, it’s time to start with the most trusted & professional solution available. Then we can proceed towards the manual ways as well. 

How to Copy Table from One Database to Another Database Automatically?

The automated method involves highly professional & advanced software which is surprisingly very easy to use. SysTools SQL Server Migrator is the solution that can end all the hassles for users without any errors.

Download Now Purchase Now

This solution comes with several advanced features as well. A few of them are listed below:

  • Repair corrupted files before migrating to another database.
  • A total of four modes for SQL database migration are present here.
  • Plenty of features to boost the migration task with selective data preference.
  • Safe & reliable solution that protects the data integrity of users’ database objects.
  • No need to transfer data from one database to another SQL Server using queries or commands.

Here’s a detailed video that users can go through for a step-by-step guide to this advanced tool.

Also Read: Top 5 SQL Server Database Migration Tools Available Now

Copy Data from One Database to Another Step by Step

Apart from the video, let’s quickly go through the step-by-step solution of the above-mentioned automated solution. Download the tool from above to get the solution at a discounted price. Then install it in your system & follow the below steps carefully.

Step-1. Launch the tool on your computer to begin the process.

launch tool to copy table from one database to another

Step-2. Select the Online or Offline Mode & add the database.

select online or offline mode

Step-3. Preview the Database Files & the Objects to migrate.

preview database objects

Step-4. Set Destination SQL Server & database for the data. 

select destination

Step-5. Hit the Export button to finish the data migration task.

copy table from one database to another

So far, this method is a complete solution & this is why IT experts, Microsoft MVPs & other industry professionals address this solution as the one top solution.

Create A Table for Executing the Manual Methods

For using the manual solutions, users first need to create a table. Then only we can start to copy table from one database to another without any hassles. To create a table, users need to follow the below-mentioned command first:

CREATE TABLE [dbo].[Employee]
(
    [EmpID] [int] NULL,
    [EmpName] [varchar](30) NULL,
    [EmpSalary] [int] NULL
)

We are creating a table named “Employee”, to begin with. Now, in the upcoming sections, we can migrate this to other databases using manual solutions.

For the upcoming commands, we’re going to address the following scenario to understand everything.

  • Server Host: localhost
  • Source Database: TechForums50
  • Destination Database: TechForums100
  • Both Databases are stored on the Same SQL Server
Also Read: Best 5 MDF Viewer Tool in the World

Using the SELECT INTO Query Method

Now, that we have created the table, it’s time to execute the SELECT INTO query. Also, users need to keep in mind that SELECT INTO cmd only copies the data & schema of a table. It is used for either migrating tables among databases or creating a new table in the destination database.

The basic command of this query is like:

SELECT * INTO DestinationDB.dbo.tableName FROM SourceDB.dbo.SourceTable

Step 1. When we look into our scenario, we can write this command as:

SELECT * INTO TechForums100.dbo.[Employee] FROM TechForums50.dbo.[Employee]

Step 2. Now, Click the F5 button to execute this command.

Step 3. Finally, Hit F8 to open Object Explorer. Here, you can select your TechForums100 database to see the table.

This solution might seem easy but due to the lack of customization features, users often feel the need for advanced features. However, we already have an automated tool for that. Therefore, this solution can be used in the case of simple table migration.

SQL Copy Table from One Database to Another with Import/Export Wizard

This solution is by using the SSMS platform & is especially for users that are not proficient in SQL Server commands.

Step: 1. Open SQL Server Management Studio to begin the task.

Step: 2. Navigate to Object Explorer, Right-Click TechForums50 DB >> Tasks >> Select the Export Data command.

Step: 3. Mention Server Name, Authentication, & Source DB name. Then, Click Next to continue.

select source DB

Step: 4. Now, Mention the Destination Database Name to proceed further.

select destination DB

Step: 5. Select the first option as shown in the image sayingCopy data from one or more tables or views. Hit the Next button.

select first option

Step: 6. Select the Tables you want to copy to another database in the prompt window.

select tables

Step: 7. Click Next on the Save & Run Wizard option & Hit the  Next button.

click next

Step: 8. Hit the Finish button.

click finish

Undoubtedly, this solution is quite hectic as it involves plenty of steps that can result in mistakes & further complications.

How to Migrate Data from One Database to Another by Generate Scripts Method

Now, when we talk about the Generate Scripts methods, it’s a bit different. Therefore, the use of this method is different too. In case users wants to migrate objects, indexes, triggers, constraints, etc along with the table, then they need to rely on this method.

Step 1. Click on database Name -> Tasks -> Generate Scripts option“.

select tasks

Step 2. In the Generate Scripts Wizard, Click on the Next button.

click next

Step 3. Select Tables for SQL copy table from one database to another & Click on the Next button.

select tables

Step 4. Enter the Destination Path for the file & Hit Next to proceed.

enter path

Step 5. Cross-Check the Source & Destination Location along with other details & Click Next.

verify data

Step 6. Hit the Finish button to end the task.

click finish

After this, users can find the script file in the selected location. They just need to run this file in their desired database & they can have the required table there.

Conclusion

Now we know how to copy table from one database to another in SQL Server without hassles. Furthermore, when we dive deeper, we can say that there are plenty of solutions out of which automated tool works best. Users must understand that one single mistake can be dangerous in such tasks. Therefore, to avoid unwanted errors, only trust the solution in which you’re having the maximum confidence.

Also Read: Top 5 SQL Recovery Tools with Utmost Safety

FAQs

Q-1. Can we execute SQL copy table from one database to another for different servers?

Ans: Using the tool, users can perform cross-server migration as well. It supports SQL Server 2022, 2019, 2017, 2016, 2014 2012, 2008/2008 R2, 2005, 2000.

Q-2. What database objects this automated tool can copy?

Ans: The tool can copy data from one database to another database like tables, views, triggers, stored procedure, rules, keys, columns, etc.

Q-3. How to copy data from one table to another table in different database in SQL if we do not have live source server?

Ans: If users do not have live server, they can use the automated tool & upload MDF file in it to execute the solution. 

Q-4. Is this automated tool free to use?

Ans: Both Yes & No. Users can download the trial edition to copy data from one database to another one.