How to Restore a Single Table in SQL Server from Backup

Restore a Single Table in SQL Server

Suppose, you have a table in your SQL Server database that has several important data items, but your table gets corrupted due to some reasons. Now you need a solution to recover the table and its data.

Methods To Restore a Single Table in SQL Server

In SQL Server, to restore a single table from SQL backup, you can choose one of the below mentioned methods. Each method has an advantage and associated disadvantages with them.

  1. Restore Database
  2. Restoring the database is one of the simplest solution which can be easily applied to SQL Server databases. To restore a single deleted table, restore your database to a different location as a separate database and give it a different name. Now place the .mdf/.ldf files in a different location or rename them during the restore. Once you have restored the full database there are several methods to "copy" the table. You can use a linked server or other techniques to move the data.

  3. Restore Log File Backup Using STOPAT
  4. To restore a Single SQL Server table, you can restore the database backup and can roll it to a point in time recovery technique. Use the STOPAT clause if your database is in the full or bulk-logged recovery model to restore the log files. This trick will overwrite all the data modifications.

    Syntax

    RESTORE DATABASE db_name
     FROM db_nameBackups
     WITH FILE=5,NORECOVERY;
     RESTORE LOG db_name
     FROM db_name Backups
     WITH FILE=5, NORECOVERY, STOPAT = 'TIME’;
     RESTORE DATABASE db_name WITH RECOVERY;

  5. BCP To Restore Database
  6. With the help of BCP you can export and import a large amount of data quickly within the same database or to other database of SQL Server. Using BCP you can setup a job like SQL Server Agent or you can create a trigger to periodically export the data from one location to another location.

  7. Database Snapshot
  8. Database snapshot is read only static view of SQL Server source database that can be used to fix the data source, but the snapshot needs to setup before the issue occurs. The database snapshot can be used only when the table is not so frequently updated (weekly or monthly updates). If the updates are done frequently on a day by day basis, then the database snapshot is not an optimal solution. In case you want to use the database snapshot as a solution, then you need to create a snapshot after every update or change done in the database.

  9. Use ‘View’ to Move the Table
  10. You can create a view to access the data from the original database which select all the data from table. Note that if you are going to create a view, then you need to rename or drop the table in the old database. You can modify the actual table in a newly created database.

    Syntax

    USE db_name;
     GO
     CREATE VIEW table_name;
     AS
     SELECT *
     FROM new_db;
     GO

Conclusion

This article describes, how to restore a single table from SQL Server database instead of restoring the whole database via different methods.

Previous
Next Post »

2 comments

Click here for comments
November 15, 2016 at 9:54 PM ×

In oracle, a table can be spooled from the database backup files likewise its not exists in SQL server.

But, in SQL server taking table from live db using views or bcp.

Reply
avatar
Unknown
admin
November 17, 2016 at 6:53 PM ×

In other words no way to just restore a random SQL table! Unless the table were placed on its own files.

Reply
avatar

EmoticonEmoticon