SQL SERVER – FIX : ERROR : Msg 3159, Level 16, State 1, Line 1 – Msg 3013, Level 16, State 1, Line 1

While moving some of the script from SQL SERVER 2000 to SQL SERVER 2005 our migration team faced following error.

Msg 3159, Level 16, State 1, Line 1
The tail of the log for the database “AdventureWorks” has not been backed up.
Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose.
Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

Following is the similar script using AdventureWorks samples database as example. This scripts works perfectly fine with SQL SERVER 2000. It gives the error in SQL SERVER 2005.

RESTORE DATABASE AdventureWorks
FROM DISK = 'C:\BackupAdventureworks.bak'
WITH MOVE 'AdventureWorks_Data' TO 'C:\Data',
MOVE 'AdventureWorks_Log' TO 'C:\Data'

The reason of error is already explained in the error detail. Requirement of backing up tail of the log for the database can be overridden by using RESTORE command. Most of the WITH clause statements can be used in combination with the others. Change the syntax of above script with addition of REPLACE in WITH clause.

ALTER DATABASE
AdventureWorks
SET SINGLE_USER WITH
ROLLBACK
IMMEDIATE

RESTORE DATABASE AdventureWorks
FROM DISK = 'C\:BackupAdventureworks.bak'
WITH MOVE 'AdventureWorks_Data' TO 'C:\Data\datafile.mdf',
MOVE 'AdventureWorks_Log' TO 'C:\Data\logfile.ldf',
REPLACE

Reference : Pinal Dave (https://blog.sqlauthority.com) ,BOL

SQL Backup and Restore, SQL Error Messages, SQL Scripts, SQL Server Security
Previous Post
SQL SERVER – 2005 Security DataSheet
Next Post
SQL SERVER – Collate – Case Sensitive SQL Query Search

Related Posts

Leave a Reply