2

it is working......

declare @dbName varchar(50)
set @dbName='myDb'
    BACKUP DATABASE @dbName TO DISK = 'c:\backup\myDb.bak'

But Why is it not working? where as both are similar query.

 BACKUP DATABASE 'mydb' TO DISK = 'c:\backup\myDb.bak'

1 Answer 1

3

The documentation says:

BACKUP DATABASE { database_name | @database_name_var } 
    TO <backup_device> [ ,...n ] 

So it takes a database name (f.e. mydb) or a variable (f.e. @dbname.) But not a string literal (f.e. 'mydb'.)

Just omit the quotes to change the string literal to a database name:

BACKUP DATABASE mydb TO DISK = 'c:\backup\myDb.bak'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.