1

I am trying to change the recovery model of the current database.

This is what I have:

DECLARE @dbName VARCHAR(50)
SELECT @dbName = DB_NAME()
ALTER DATABASE @dbName SET RECOVERY SIMPLE WITH NO_WAIT

@dbName gives me:

Incorrect syntax near '@dbName'.

I tried:

ALTER DATABASE database_id SET RECOVERY SIMPLE WITH NO_WAIT

database_id gives me:

Msg 5011, Level 14, State 5, Line 3 User does not have permission to alter database 'database_id', the database does not exist, or the database is not in a state that allows access checks.

How should I execute this on the current database?

4

1 回答 1

5
DECLARE @sql NVARCHAR(MAX) = N'ALTER DATABASE ' 
  + QUOTENAME(DB_NAME())
  + ' SET RECOVERY SIMPLE WITH NO_WAIT;';

EXEC sp_executesql @sql;
于 2013-03-04T22:03:37.970 回答