Loading...

We've detected that your browser language is Chinese. Would you like to visit our Chinese website? [ Dismiss ]
By: Dervish

Why Copy a Table from One Database to Another?

Copying a table from one database to another is a common task for SQL Server administrators, developers, and database engineers. Whether you need to migrate data, create a testing environment, duplicate production data, or move tables between different servers, SQL Server provides several ways to complete the task.

The best method depends on your requirements:

  • For quickly copying table data within the same SQL Server instance, SQL queries such as SELECT INTO and INSERT INTO SELECT are usually the simplest options.
  • For copying tables with structure, indexes, and constraints, SQL Server Management Studio (SSMS) provides more complete control.
  • For moving tables between different SQL Server instances, you can use Linked Server queries or the Import and Export Wizard.
  • For continuous synchronization or large-scale database migration, an enterprise replication solution may be more suitable.

In this guide, we will explain 5 practical methods to copy a table from one SQL database to another.

sql-copy-table-from-one-database-to-another

Method 1: Copy SQL Table Using SELECT INTO Statement

The SELECT INTO statement is one of the easiest ways to copy tables from one SQL database to another. It allows you to create a new table in the destination database and copy data from an existing table in the source database with a single SQL query.

This method is commonly used when:

  • The destination table does not already exist.
  • You only need to copy table data and basic structure.
  • You want a quick one-time copy operation.

However, SELECT INTO has some limitations. It copies columns and data types but does not automatically copy indexes, constraints, triggers, or permissions.

Step 1. Open SQL Server Management Studio and Connect to Your Database.

Open SQL Server Management Studio and connect to the SQL Server instance that contains the source database.

After connecting:

  1. Expand Databases in Object Explorer.
  2. Identify the source database containing the table you want to copy.
  3. Click New Query to open a SQL query window.

open-new-query-ssms

Step 2. Execute the SELECT INTO Statement.

Use the following query format:

SQL
SELECT *
INTO DestinationDatabase.dbo.NewTableName
FROM SourceDatabase.dbo.SourceTableName;

For example:

SQL
SELECT *
INTO SalesArchive.dbo.CustomerBackup
FROM SalesDB.dbo.Customer;
This command will:
  • Read data from the Customer table in the SalesDB database.
  • Create a new CustomerBackup table in the SalesArchive database.
  • Copy all records into the new table.

After running the query, SQL Server will automatically create the destination table.

Step 3. Verify the Copied Table

After the query completes successfully:

  1. Refresh the destination database.
  2. Expand Tables.
  3. Locate the newly created table.
  4. Run a query to confirm that the data has been copied.

Example:

SQL
SELECT *
FROM SalesArchive.dbo.CustomerBackup;

You can compare the number of records between the source and destination tables:

SQL
SELECT COUNT(*)
FROM SalesDB.dbo.Customer;

SELECT COUNT(*)
FROM SalesArchive.dbo.CustomerBackup;

Advantages

  • Simple and fast for one-time table copying.
  • Requires only a basic SQL query.
  • Automatically creates the destination table.
  • Suitable for copying large amounts of data within the same SQL Server instance.

Limitations

  • Does not copy indexes.
  • Does not copy primary keys or foreign keys.
  • Does not copy triggers.
  • Does not preserve all table properties.

If you need to copy a table with its complete database objects, consider using SQL Server Management Studio or scripting methods.

Method 2: Copy SQL Table Using INSERT INTO SELECT Query

Another common method to copy a SQL table from one database to another is using the INSERT INTO SELECT statement.

Unlike SELECT INTO, this method requires the destination table to already exist. Instead of creating a new table, SQL Server inserts data into an existing table structure.

This approach is useful when:

  • The target table has already been created.
  • You need more control over which columns are copied.
  • You only want to copy specific records.

Step 1. Create the Destination Table.

Before using INSERT INTO SELECT, create the target table in the destination database.

For example:

SQL
CREATE TABLE ArchiveDB.dbo.EmployeeBackup
(
    EmployeeID INT,
    EmployeeName VARCHAR(100),
    Department VARCHAR(50)
);

The destination table structure should match the source table columns you plan to copy.

Step 2. Run the INSERT INTO SELECT Query.

The basic syntax is:

SQL
INSERT INTO DestinationDatabase.dbo.TargetTable
SELECT *
FROM SourceDatabase.dbo.SourceTable;

Example:

SQL
INSERT INTO ArchiveDB.dbo.EmployeeBackup
SELECT *
FROM HRDatabase.dbo.Employee;

This copies all rows from the Employee table in HRDatabase into the EmployeeBackup table in ArchiveDB.

Step 3. Copy Selected Columns or Filter Specific Data.

One advantage of INSERT INTO SELECT is that you can control what data is copied.

For example, copy only selected columns:

SQL
INSERT INTO ArchiveDB.dbo.EmployeeBackup
(
    EmployeeID,
    EmployeeName
)
SELECT
    EmployeeID,
    EmployeeName
FROM HRDatabase.dbo.Employee;

You can also copy only specific records by adding a WHERE condition:

SQL
INSERT INTO ArchiveDB.dbo.EmployeeBackup
SELECT *
FROM HRDatabase.dbo.Employee
WHERE Department = 'IT';

Step 4. Verify the Copied Data.

After execution, verify that the destination table contains the expected data:

SQL
SELECT *
FROM ArchiveDB.dbo.EmployeeBackup;

You can also compare record counts:

SQL
SELECT COUNT(*)
FROM HRDatabase.dbo.Employee;

SELECT COUNT(*)
FROM ArchiveDB.dbo.EmployeeBackup;

SELECT INTO vs INSERT INTO SELECT: Which Method Should You Choose?

Feature SELECT INTO INSERT INTO SELECT
Creates a new table automatically Yes No
Requires destination table No Yes
Copies table data Yes Yes
Supports selecting specific columns Limited Yes
Supports filtering records Limited Yes
Copies indexes and constraints No No
Best for Quick table copy Controlled data transfer

For simple one-time table duplication, SELECT INTO is usually faster. If you need more control over the copied data, INSERT INTO SELECT is a better option.

Method 3: SQL Server Management Studio Copy Table from One Database to Another

SQL Server Management Studio (SSMS) provides a graphical way to copy tables between databases without manually writing SQL statements. Compared with SELECT INTO and INSERT INTO SELECT, SSMS allows you to generate scripts that include more database objects, such as table structure, indexes, constraints, and data.

This method is suitable when you need to:

  • Copy tables together with their schema.
  • Move tables to another database for testing or development.
  • Preserve table definitions instead of copying only raw data.
  • Perform a controlled one-time table migration.

In SSMS, the most common way to copy a table is by using the Generate Scripts Wizard.

Step 1. Open Generate Scripts Wizard in SSMS.

First, open SQL Server Management Studio and connect to your SQL Server instance.

Follow these steps:

  1. Expand Databases in Object Explorer.
  2. Right-click the source database that contains the table.
  3. Select Tasks.
  4. Click Generate Scripts.

generate-scripts

Step 2. Select the Table to Copy.

The Generate Scripts Wizard will guide you through the scripting process.

In the wizard:

  1. Click Next on the welcome page.
  2. Select Choose specific database objects.
  3. Expand Tables.
  4. Select the table you want to copy.
  5. Click Next.

For example, if you want to copy the Customer table:

Source Database
└── Tables
└── dbo.Customer

will be selected.

select-the-sql-table-to-copy

Step 3. Configure Script Options.

In the Script Options page, you can decide what SQL Server should include in the generated script.

Important settings include:

Types of data to script

Set:

Types of data to script:
Schema and Data

This ensures that SSMS generates both:

  • CREATE TABLE statements.
  • INSERT statements for existing data.

Other options include:

  • Schema only
  • Data only

For a complete table copy, choose Schema and Data.

Advanced Options

You can also configure additional settings:

  • Script indexes
  • Script primary keys
  • Script foreign keys
  • Script triggers

These options help preserve the original table design.

types-of-data-to-script

Step 4. Generate the SQL Script.

After selecting the required options:

  1. Choose where to save the generated script.
  2. Click Next.
  3. Review the selections.
  4. Click Finish.

SSMS will generate a SQL script similar to:

SQL
CREATE TABLE [dbo].[Customer]
(
    [CustomerID] INT,
    [CustomerName] VARCHAR(100)
);

INSERT INTO [dbo].[Customer]
VALUES
(1, 'John Smith');

This script can then be executed in another database.

Step 5. Execute the Script in the Destination Database.

To copy the table:

  1. Connect to the destination database.
  2. Open a new query window.
  3. Paste the generated script.
  4. Click Execute.

After execution, SQL Server will create the table and insert the data.

Advantages

  • Provides a user-friendly graphical interface.
  • Can copy table structure and data.
  • Supports indexes, keys, and constraints.
  • Does not require advanced SQL knowledge.

Limitations

  • Not ideal for very large tables.
  • Requires manual operation.
  • Not designed for continuous synchronization.
  • Additional configuration may be required for cross-server transfers.

For occasional table copying, SSMS is a convenient solution. However, enterprises that need automated synchronization between databases may require a dedicated replication solution.

Method 4: Copy SQL Table from One Database to Another Different Server

Copying a SQL table between different servers is more challenging than copying tables within the same SQL Server instance. When the source and destination databases are located on separate servers, you need to establish communication between the servers or use a data transfer tool.

This scenario is common when organizations need to:

  • Move tables from a production server to a test server.
  • Transfer data between different SQL Server environments.
  • Perform database migration between servers.
  • Copy tables between on-premises and cloud SQL Server instances.

There are two common approaches: Using SQL Server Linked Server with queries and Using SQL Server Import and Export Wizard.

Option 1. Copy Table Between SQL Servers Using Linked Server Query

A Linked Server allows one SQL Server instance to access data from another SQL Server instance. After configuring a Linked Server connection, you can use SQL queries to copy data directly between databases.

Step 1. Configure a Linked Server Connection.

In SSMS:

  1. Connect to the destination SQL Server.
  2. Expand Server Objects.
  3. Right-click Linked Servers.
  4. Select New Linked Server.

Configure:

  • Linked server name.
  • Source SQL Server connection information.
  • Authentication method.

Example:

Linked Server Name:
SourceSQLServer

new-linked-server-ssms

Step 2. Test the Linked Server Connection.

Before copying data, verify that the connection works.

Run:

SQL
EXEC sp_testlinkedserver 
'SourceSQLServer';

Step 3. Copy Table Data Using a Cross-Server Query.

After creating the Linked Server, use a four-part object name:

LinkedServer.Database.Schema.Table

Example:

SQL
INSERT INTO DestinationDB.dbo.Customer
SELECT *
FROM SourceSQLServer.SourceDB.dbo.Customer;

This query copies data:

     Source SQL Server    
                  |                        
                  |                        
       Linked Server           
                  |                        
                  |                        
Destination SQL Server

Option 2. Copy SQL Table Between Servers Using Import and Export Wizard

SQL Server Import and Export Wizard is another built-in method for moving tables between different servers.

It is suitable when:

  • You prefer a graphical interface.
  • You need to copy multiple tables.
  • You need data transformation during migration.

Step 1. Launch Import and Export Wizard.

In SSMS:

  1. Right-click the source database.
  2. Select:

Tasks → Export Data

  1. The SQL Server Import and Export Wizard will open.

export-data

Step 2. Select Source and Destination Servers.

Configure:

Data Source

Select:

  • SQL Server instance.
  • Database containing the source table.

Destination

Select:

  • Target SQL Server instance.
  • Destination database.

Step 3. Select Tables to Transfer.

Choose:

Copy data from one or more tables

Then select the tables you want to copy.

Source:
SalesDB.dbo.OrderDetails

Destination:
ArchiveDB.dbo.OrderDetails

column-mapping

Step 4. Complete the Data Transfer.

Review the configuration:

  1. Confirm source and destination settings.
  2. Click Finish.
  3. Wait for the transfer process to complete.

After completion, verify the copied table in the destination database.

execution-successful

Comparing Different Methods for Copying SQL Tables

Method Best For Requires Target Table Supports Different Servers Copies Schema
SELECT INTO Quick table copy No Limited Basic
INSERT INTO SELECT Controlled data transfer Yes Limited No
SSMS Generate Scripts Copy schema and data No Yes Yes
Linked Server Query Cross-server copying Yes Yes No
Import/Export Wizard GUI-based migration No Yes Yes

What Method Should You Choose?

For simple one-time table copying:

  • Use SELECT INTO when you need a fast copy.
  • Use INSERT INTO SELECT when you need more control over data selection.

For copying tables with database objects:

  • Use SSMS Generate Scripts.

For copying tables between different SQL Server instances:

  • Use Linked Server or Import/Export Wizard.

However, these methods are mainly designed for manual or one-time transfers. If you need continuous synchronization, real-time replication, or automated database migration, an enterprise data replication solution is more suitable.

Method 5: Automatically Copy and Synchronize SQL Tables with i2Stream

The methods above are suitable for one-time SQL table copying. However, enterprises often need continuous data synchronization, low-downtime database migration, or replication between different database platforms.

i2Stream is a real-time database replication and synchronization software that helps organizations automatically replicate data changes between heterogeneous database environments. It captures database changes and continuously delivers them to target systems, reducing the need for manual data copying.

  • Real-time database replication: Continuously synchronize INSERT, UPDATE, and DELETE operations between source and target databases.
  • Heterogeneous database support: Replicate data across platforms such as SQL Server, Oracle, MySQL, and PostgreSQL.
  • CDC-based data capture: Capture database changes efficiently without repeated full-table transfers.
  • Low-downtime migration: Keep source and target databases synchronized during database migration projects.
FREE Trial for 60-Day

    For occasional table copies, SQL queries and SSMS are usually enough. For enterprise scenarios that require automated synchronization or continuous replication, i2Stream provides a more efficient solution.

    Common Issues When Copying SQL Tables Between Databases

    Although SQL Server provides multiple ways to copy tables, database administrators may encounter several challenges during the process.

    Understanding these issues helps you choose the right method and avoid unexpected problems.

    1. Table Structure Is Not Fully Copied

    A common issue with methods such as SELECT INTO is that only columns and data are copied.

    Objects that may not be transferred include:

    • Primary keys.
    • Foreign keys.
    • Indexes.
    • Triggers.
    • Default constraints.

    For example, after copying a table using:

    SQL
    SELECT *
    INTO NewDatabase.dbo.Customer
    FROM OldDatabase.dbo.Customer;
    

    the new table may contain the data but lack the original performance optimizations and relationships.

    For a complete copy, consider using:

    • SSMS Generate Scripts.
    • Database migration tools.
    • Replication solutions.

    2. Copying Large Tables Can Affect Performance

    When copying millions or billions of rows, simple SQL statements may impact database performance.

    Potential problems include:

    • High transaction log usage.
    • Long execution times.
    • Blocking on production databases.
    • Network bandwidth consumption.

    For large-scale data movement, consider:

    • Batch processing.
    • Scheduled migration windows.
    • Incremental synchronization.
    • CDC-based replication.

    3. Cross-Server Copy Requires Proper Permissions

    When copying tables between different SQL Server instances, permission issues are common.

    Typical problems include:

    • Linked Server authentication failures.
    • Insufficient database permissions.
    • Network connectivity restrictions.

    Before performing a cross-server copy, verify:

    • SQL Server connectivity.
    • User permissions.
    • Firewall settings.
    • Authentication configuration.

    4. One-Time Copy vs Continuous Synchronization

    SQL table copy methods are effective when you need to move data once.

    However, they are not designed for scenarios where data changes continuously.

    For example:

    A company migrating from SQL Server to PostgreSQL may need to keep both databases synchronized during the migration period.

    Running manual copy commands repeatedly can be:

    • Time-consuming.
    • Error-prone.
    • Difficult to maintain.

    For continuous data synchronization, a real-time replication solution is usually a better approach.

    FAQs: SQL Copy Table from One Database to Another

    1. How do I copy a table from one database to another in SQL Server?

    You can copy a table from one SQL Server database to another using several methods, including SELECT INTO, INSERT INTO SELECT, SQL Server Management Studio (SSMS), and Import and Export Wizard.

    For a quick copy:

    SQL
    SELECT *
    INTO TargetDatabase.dbo.TableName
    FROM SourceDatabase.dbo.TableName;
    

    For more control over copied columns and data:

    SQL
    INSERT INTO TargetDatabase.dbo.TableName
    SELECT *
    FROM SourceDatabase.dbo.TableName;
    

    2. How do I copy tables from one SQL database to another different server?

    To copy tables between different SQL Server instances, you can use:

    • Linked Server queries.
    • SQL Server Import and Export Wizard.
    • Database migration tools.

    Linked Server allows you to execute cross-server SQL queries, while Import and Export Wizard provides a graphical transfer process.

    3. Can SELECT INTO copy indexes and constraints?

    No. SELECT INTO copies:

    • Column definitions.
    • Data types.
    • Table data.

    It does not copy:

    • Indexes.
    • Primary keys.
    • Foreign keys.
    • Triggers.

    If you need to preserve these objects, use SSMS Generate Scripts or another migration approach.

    4. How do I copy a table using SQL Server Management Studio?

    In SSMS, you can copy a table by:

    1. Right-clicking the source database.
    2. Selecting Tasks → Generate Scripts.
    3. Choosing the table.
    4. Selecting Schema and Data.
    5. Running the generated script in the target database.

    This method copies both the table structure and data.

    5. What is the best way to copy SQL tables continuously?

    For continuous table synchronization, manual SQL scripts are not ideal because they only perform one-time transfers.

    A CDC-based replication solution such as i2Stream can automatically capture database changes and replicate them to target systems in real time.

    Conclusion

    Copying a table from one SQL Server database to another can be done using different methods depending on your needs. For simple one-time transfers, SQL queries and SSMS provide convenient solutions.

    For enterprises that require continuous synchronization, low-downtime migration, or cross-platform database replication, i2Stream provides an automated and reliable way to keep data synchronized across different database environments.

    A core member of info2soft's technical team, specializing in enterprise data management and IT operations. Focused on data backup, disaster recovery solutions, and product iteration optimization, he breaks down technical challenges with practical experience to deliver highly implementable content.

    More Related Articles

    Table of Contents:
    Stay Updated on Latest Tips
    Subscribe to our newsletter for the latest insights, news, exclusive content. You can unsubscribe at any time.
    Subscribe
    Ready to Enhance Business Data Security?
    Start a 60-day free trial or view demo to see how Info2soft protects enterprise data.
    Please fill out the form and submit it, our customer service representative will contact you soon.
    By submitting this form, I confirm that I have read and agree to the Privacy Notice.
    {{ isSubmitting ? 'Submitting...' : 'Submit' }}