我写了一个简单的程序来收缩数据库日志,只需要输入数据库名称:
ALTER proc [dbo].[sp_shrinkDBAndDBLog]
@databaseName nvarchar(100)
as
begin
declare @logName nvarchar(100),
@dynamicSQL nvarchar(500)
set @dynamicSQL='ALTER DATABASE '+@databaseName+' SET RECOVERY SIMPLE WITH NO_WAIT'
exec(@dynamicSQL)
--select name from HLJEDI_SYS.sys.sysfiles where groupid=0;
set @dynamicSQL=N'select @logName= name from '+@databaseName+'.sys.database_files where type_desc=''LOG'''
exec sp_executesql @dynamicSQL,N'@logName nvarchar(100) output',@logName output
--select * from sys.sysfiles where groupid=0
set @dynamicSQL='DBCC SHRINKFILE (N'''+@logName+''',11,TRUNCATEONLY)'
exec(@dynamicSQL)
--DBCC SHRINKFILE (N'CUC_OA_LOG' , 11, TRUNCATEONLY)
set @dynamicSQL='ALTER DATABASE '+@databaseName+' SET RECOVERY FULL WITH NO_WAIT'
exec(@dynamicSQL)
--ALTER DATABASE OA SET RECOVERY FULL --(Restore to Full Schema)
end
但是当我执行时:
exec sp_shrinkDBAndDBLog 'DBName'
它有错误:sys.database_files 找不到数据库 'master' 文件 'eca2_log'。该文件已被删除并且不存在。</p>
问题是什么?谢谢你告诉我并展示细节和王子。