Howtos / Articles

Restore Microsoft SQL Database Using T-SQL

This guide will show you how to restore a Microsoft SQL database using T-SQL commands rather than using the wizards in SQL Management Studio. This has the added benefit of being able to be scripted if needed.

Restoring a Microsoft SQL database:

RESTORE DATABASE [database_name] FROM DISK='c:\path\to\backup\file.bak'

Replace ‘database_name’ with the name of the database you want to restore to.

Eg:

RESTORE DATABASE [testing] FROM DISK='C:\temp\testing.bak'

Sample output:

Processed 312 pages for database 'testing', file 'Testing' on file 1.
Processed 3 pages for database 'testing', file 'Testing_log' on file 1.
RESTORE DATABASE successfully processed 315 pages in 0.417 seconds (5.885 MB/sec).

By default, this will overwrite the database if it already exists.

The path to the SQL backup file needs to be a path on the server running SQL server. This means that if you run the restore script from a client workstation, make sure the path to the backup file refers to a path on the server, and not a path on the clients workstation.

 



Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>