(MSSQL)Reducing LDF file size

1. 查詢’DBNAME_log’實際名稱

1
SELECT * FROM SYS.DATABASE_FILES

2. 將資料庫改成簡單(simple)模式

1
ALTER DATABASE DBNAME SET RECOVERY SIMPLE

3. SHRINKFILE

1
2
3
USE *DBNAME*
GO
DBCC SHRINKFILE('DBNAME_log',2)

SHRINKFILE語法

1
2
3
4
5
6
7
8
DBCC SHRINKFILE   
(
{ file_name | file_id }
{ [ , EMPTYFILE ]
| [ [ , target_size ] [ , { NOTRUNCATE | TRUNCATEONLY } ] ]
}
)
[ WITH NO_INFOMSGS ]

4. 將資料庫改回完整(FULL) 模式

1
ALTER DATABASE DBNAME SET RECOVERY FULL