Shrink Transaction log file of a database

-- To Find the ldf file names for a database
USE DatabaseName
SELECT file_id, name, type_desc, physical_name, size, max_size
FROM sys.database_files


DBCC LOGINFO('DatabaseName')
USE DatabaseName;
GO

ALTER DATABASE DatabaseName
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (Databaselogical_LogFileName, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE DatabaseName
SET RECOVERY FULL;
GO


--**** Extra Helping Script to get all databases names and their file names and file sizes****

SELECT
    db.name AS DBName,
    type_desc AS FileType,
    Physical_Name AS Location,
Mf.name AS logicalFileName,
Mf.size
FROM
    sys.master_files mf
INNER JOIN
    sys.databases db ON db.database_id = mf.database_id
order by mf.size DESC

Comments

Popular posts from this blog

TSQL To Get All the Names of tables and Databases whose data have changed in last 24 Hours

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases

Apply paging in procedure