Making a database Restore in Sql 2005

  • In Sql 2005 how can a database restore be done by TSQL commands rather than using the Microsoft SQL Server Management Studio?

  • Hi there,

    There are quite a few ways to restore a database (From a backup file, a snapshot etc).

    This is just a basic example:

    RESTORE DATABASE [YourDatabase]

    FROM DISK = N'path to backup'

    WITH FILE = 1,

    NOUNLOAD,

    STATS = 10

    GO

    But try to readup on this in Books Online as well.

  • Definately a Books Online topic. I did write a primer on backups & restores over here[/url]. I'd still hit BOL first.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • A very good article Grant

  • Thank you, but Books Online is better and much more complete.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Sure, to an extent.

    But BOL doesn't really explain topics from a 'business-needs' point of view. With your article you can actually imagine/think of scenario's where certain options work better than other.

  • You can use this proc to restore your database...

    ------------------------------------------------------

    EXEC master.dbo.xp_restore_database

    @database= 'Pubs'--Database Name

    ,@filename= 'C:\Pubs.bak' -- Backup File path

    ,@filenumber=1

    ,@WITH='REPLACE'

    ,@WITH='RECOVERY'

    ,@WITH = 'MOVE "Pubs_Data" TO "C:\Data\Pubs_Data.mdf"'

    ,@WITH = 'MOVE "Pubs_Log" TO "C:\Data\Pubs_Log.ldf"'

    ,@servername = '??' --SET SQL INSTANCE HERE

    -------------------------------------------------------

    Basit Ali Farooq
    MCITP Database Administrator
    Microsoft Certified Professional Developer (Web Applications)
    Microsoft Certified Database Administrator
    Microsoft Certified Systems Engineer
    Microsoft Certified Systems Administrator
    CIW Security Analyst
    Cisco Certified Network Associate

  • Thank you again. Feedback, positive or negative, is always welcome.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply