Академический Документы
Профессиональный Документы
Культура Документы
Introduction
You know there is always an issue - the log file growing very fast and big. If you have
plenty of storage, then this might not be a problem for you. Anyway, this is no exception in
the latest version of SQL, we still have to do something to truncate and shrink these files.
Implementation
SELECT
--DB_NAME(database_id) AS DatabaseName,
--Physical_Name,
Name AS Logical_Name,
(size*8)/1024 SizeMB
FROM
sys.master_files
WHERE
DB_NAME(database_id) = 'tempdb'
GO
Output
USE tempdb;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE tempdb
SET RECOVERY SIMPLE WITH NO_WAIT;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE(tempdb_log, 1); --file_name is the logical name of the file
to be shrink
GO
-- Reset the database recovery model.
ALTER DATABASE tempdb
SET RECOVERY FULL WITH NO_WAIT;
GO
SELECT
--DB_NAME(database_id) AS DatabaseName,
--Physical_Name,
Name AS Logical_Name,
(size*8)/1024 SizeMB
FROM
sys.master_files
WHERE
DB_NAME(database_id) = 'tempdb'
GO