articles

Home / DeveloperSection / Articles / How to Backup a Table in SQL Server

How to Backup a Table in SQL Server

AVADHESH PATEL5482 15-Sep-2012

There is not standard method for backing up a table in SQL Server.  A common request I receive from clients is to only backup specific tables within a database.  Well, unfortunately there is no out of the box method for doing this akin to a database backup so we need to roll our own way.

It is usually done one of two ways.  The first is to use a select into method to copy the table.  The other way is to script the table out using the Generate Scripts Tasks.  Both methods have positives and negatives.  First off, the SELECT INTO Method is by far the fastest.  It can copy a large number of rows very quickly, the downfall to this however, is that it does not carry over the Keys, Indexes or Constraints.  The Generate Scripts method is slow (and I don’t recommend it for very large tables), however it can facilitate copying over any of the other objects associated with the table.  Let’s look at the generate scripts task:

First, right click on the database that contains the table you want to backup and choose Tasks -> Generate Scripts.

How to Backup a Table in SQL Server

The Generate Scripts Wizard Appears.  Select “Next” past the splash screen then select the database that contains the table.  The next screen that appears is the Script Options.

How to Backup a Table in SQL Server

Scroll down on the script options until you see Table/View Options.  We want the following to be true: Check Constraints, Script Data, Foreign Keys, Primary Keys, Triggers, & Unique Keys.  (Or you can choose whatever you need of course).  Select Next and we are presented with the Select Object Types Screen.

How to Backup a Table in SQL Server

Select Tables and hit next.  Lastly, choose the table or tables you want to backup and hit next.

 

How to Backup a Table in SQL Server

The last dialog provides the medium you want to output the script to.  If you are backing up a large table, I suggest you output to a file.



Updated 18-Apr-2020
Avadhesh Kumar Patel District Project Manager - Aligarh 14 months work experience in Panchayati Raj Department Sector as District Project Manager & 12 months work experience in IT Sector as Software Engineer. :-)

Leave Comment

Comments

Liked By