Click here to Skip to main content
13,457,828 members
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 14 Jul 2012

How to Copy a SQL Server Table?

, 14 Jul 2012
Rate this:
Please Sign up or sign in to vote.
Copy a SQL Server table


In this tip, I will show you the various ways of copying a SQL Server table. The first method of copying is the simplest way to copy a table into another (new) table in the same SQL Server database. You have to keep in mind that this way of copying does not copy constraints and indexes. The following illustrates a code template and a sample usage:

select * into <destination table> from <source table>


Select * into employee_backup from employee 

We can also select only a few columns into the destination table like below:

select col1, col2, col3 into <destination table>
from <source table>


Select empId, empFirstName, empLastName, emgAge into employee_backup
from employee

Use this to copy only the structure of the source table.

select * into <destination table> from <source table> where 1 = 2


select * into employee_backup from employee where 1=2

Use this to copy a table across two databases in the same SQL Server instance.

select * into <destination database.dbo.destination table>
from <source database.dbo.source table>


select * into Mydatabase2.dbo.employee_backup
from mydatabase1.dbo.employee 

Any one of the following methods can be employed to copy a table into a destination database on a different SQL Server.

  1. Data Transformation Service (DTS) – SQL Server 2000
  2. SQL Server Integration Service (SSIS) – SQL Server 2005
  3. SQL Server “Export Data” task – SQL Server 2000/2005
  4. Create a linked Server of the destination SQL Server on the source SQL Server and then copy the table – SQL Server 2000/ 2005
  5. We can also use sp_generate_inserts to generate data insertion scripts and then run the insert scripts
  6. I almost forgot this ;) you can open the source table , select the row(s), copy (ctrl + C) the row(s), open the destination table and then paste (ctrl + V) the row(s)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sudheer Reddy Battula
United States United States
Sudheer Reddy Battula - Caveman's Blog

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Member 101493835-Nov-14 0:59
memberMember 101493835-Nov-14 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180323.1 | Last Updated 15 Jul 2012
Article Copyright 2012 by Sudheer Reddy Battula
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid