Copying a table between databases moves structure and/or data from one database to another within SQL Server.
Move data to a new environment, split monoliths, create reporting databases, or back-up critical tables without full restores.
Use SELECT INTO
with fully-qualified names to create the table in the target database and populate it in one step.
SELECT *INTO ReportingDB.dbo.CustomersFROM ProductionDB.dbo.Customers;
Pre-create the table, then run INSERT INTO ... SELECT
.This preserves custom definitions, constraints, or indexes.
INSERT INTO ReportingDB.dbo.Customers (id,name,email,created_at)SELECT id,name,email,created_atFROM ProductionDB.dbo.Customers;
Create a linked server or use OPENROWSET
. Then reference the four-part name that includes the linked server.
SELECT *INTO [REMOTE].SalesDB.dbo.OrdersFROM LocalDB.dbo.Orders;
Script the table using SSMS (right-click ➜ Script Table as ➜ CREATE To).Run the script in the target database before the data copy.
Copy in batches with TOP (N)
or a date filter, disable non-clustered indexes, and enable minimal-logged operations by using SIMPLE recovery.
Unqualified names: Omitting the database name writes data to the source database again. Always include TargetDB.Schema.Table
.
Identity insert errors: Copying data with identity columns fails if the identity property is set.Add SET IDENTITY_INSERT TargetDB.dbo.Table ON
for explicit identity values.
SSMS Import/Export Wizard, BCP, and SSIS offer GUI or command-line alternatives when T-SQL is not enough.
Use SELECT INTO
for quick cloning, INSERT INTO ... SELECT
for existing tables, and linked servers for cross-instance copies. Always script constraints first.
.
No. It only copies the table structure and data. Script indexes separately or re-create them afterward.
Create the table with SELECT TOP 0 * INTO ...
. This copies columns but leaves the table empty.
Copy in smaller batches using a key column filter or TOP (N)
, and run during low-traffic windows.