Restore database using SQL script

Olga Loseva -

In the example below name of the database is EB2010_Demo002
Path to the backup file is C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup
Physical name of the file is EB2010.bak
RESTORE DATABASE [EB2010_Demo002] FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\EB2010.bak' WITH FILE = 1, MOVE N'EB2010' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\EB2010_Demo002.mdf', MOVE N'EB2010_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\EB2010_Demo002_log.LDF', NOUNLOAD, STATS = 10
Have more questions? Submit a request


  • Avatar
    Sviatoslav Bulash

    1. Make a backup of databse
    2. Create a new databse and then put it offline, using comman in query editor:
    alter database "NEW DB NAME" set offline WITH ROLLBACK IMMEDIATE

    3. In sql query editor run:
    RESTORE filelistonly FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.SCORPIONSQL\MSSQL\Backup\WSS_Content.bak'

    From this we get names of DB files

    After execution run:
    FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.SCORPIONSQL\MSSQL\Backup\WSS_Content.bak' WITH
    MOVE 'WSS_Content' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.SCORPIONSQL\MSSQL\DATA\WNEW DB NAME.mdf',
    MOVE 'WSS_Content_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.SCORPIONSQL\MSSQL\DATA\NEW DB NAME.ldf'

Powered by Zendesk