Truncar DB
Truncar DB
Truncar DB
@intRecoveryModel SMALLINT
@intNumTotalBD SMALLINT
@intContBD SMALLINT=1
@intBDID INT
@strBDName VARCHAR(4000)
@strSQL AS NVARCHAR(4000)
--PRINT @strsQL
DECLARE @intLogTotal AS SMALLINT
DECLARE @intPos AS SMALLINT=1
DECLARE @strLogFile AS VARCHAR(4000)
INSERT INTO #tblLog (LogFilename)
SELECT name FROM sys.master_files
WHERE database_id=@intBDID AND type=1
SELECT @intLogTotal=COUNT(*)
FROM #tblLog
WHILE @intPos<=@intLogTotal
BEGIN
SELECT @strLogFile=LogFileName
FROM #tblLog WHERE IDRowLog=@intPos
SET @strSQL='USE '+@strBDName+' DBCC SHRINKFILE('+@strLogFile+')'
EXEC sp_executesql @strSQL
--PRINT @strSQL
SET @intPos+=1
END
TRUNCATE TABLE #tblLog
IF @intRecoveryModel=1
SET @strSQL='ALTER DATABASE '+@strBDName+' SET RECOVERY FULL'
ELSE
SET @strSQL='ALTER DATABASE '+@strBDName+ ' SET RECOVERY
BULK_LOGGED'
exec sp_executesql @strSQL
--PRINT @strSQL
SET @intContBD+=1
END
DROP TABLE #tblLog
Aun as, tambin existen otras formas de lograr el mismo objetivo, con lo que podis evaluar
la opcin que ms os guste o entendis mejor.
Enjoy T-SQL!