SQL日志截断

use [****]
DECLARE @DataName nvarchar(100)
Select @DataName=Name From Master..SysDataBases Where DbId=(Select Dbid From Master..SysProcesses Where Spid = @@spid)
PRINT @DataName
DECLARE @LogFileLogicalName sysname
SELECT @LogFileLogicalName=Name FROM sys.database_files WHERE Type=1
PRINT @LogFileLogicalName
DECLARE @sql varchar(255)
--go
-- 改为简单模式Truncate the log by changing the database recovery model to SIMPLE.
SET @sql='ALTER DATABASE ['+@DataName+'] SET RECOVERY SIMPLE;'
EXEC (@sql)
--go截断
DBCC SHRINKFILE (@LogFileLogicalName, 1024);
--GO
-- 恢复为完全模式Reset the database recovery model.
SET @sql='ALTER DATABASE ['+@DataName+'] SET RECOVERY FULL;'
GO

你可能感兴趣的:(sql)