SQL Server: Database stuck in “Restoring” state

前端 未结 26 2082
后悔当初
后悔当初 2020-11-28 17:09

I backed up a database:

BACKUP DATABASE MyDatabase
TO DISK = \'MyDatabase.bak\'
WITH INIT --overwrite existing

And then tried to restore it

26条回答
  •  再見小時候
    2020-11-28 17:36

    If you want to restore an SQL Server database from a backup file, you can use the following script:

    RESTORE DATABASE [MyDatabase] -- which database to restore
    FROM DISK = N'X:\MyDatabase.bak' -- location of the database backup
    WITH 
        FILE = 1, -- restore from a backup file
        -- declare where the file groups should be located (can be more than two)
        MOVE N'MyDatabase_Data' TO N'D:\SSDPATH\MyDatabase.mdf',
        MOVE N'MyDatabase_Log' TO N'E:\HDDPATH\MyDatabase.ldf',
        -- Tape option; only relevant if you backup from magnetic tape
        NOUNLOAD,
        -- brings the database online after the database got restored
        -- use this option when you don't want to restore incremental backups
        -- use NORECOVERY when you want to restore differential and incremental backup files
        RECOVERY,
        -- replace existing database with the backup 
        -- deletes the existing database
        REPLACE, 
        -- print log message for every 1 percent of restore
        STATS = 1;
    

提交回复
热议问题