Saturday, May 24, 2014

Restoring a database from a backup using T-SQL (Transact SQL)

If you refer to MSDN for guidance on how to accomplish this, you will probably encounter these 2 articles:


RESTORE (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms186858.aspx


How to: Restore a Database to a New Location and Name (Transact-SQL)
http://technet.microsoft.com/en-us/library/ms190447%28v=sql.105%29.aspx

Unfortunately, the provided examples are dependent on the usage of a backup device.  If you do not want to bother with creating a backup device, then you are better off following this article: http://blog.sqlauthority.com/2007/02/25/sql-server-restore-database-backup-using-sql-script-t-sql/

Of course, if you have an older database backup and want to update the compatibility level to the latest version of SQL Server, then you will also have to run this command:


ALTER DATABASE Compatibility Level (Transact-SQL)
http://msdn.microsoft.com/en-us/library/bb510680%28v=sql.120%29.aspx

No comments:

Post a Comment