USE [YourDatabaseNameHere]
GO
SELECT *
FROM sysfiles
WHERE name LIKE '%LOG%'
GO
Second,set the database recovery model to 'simple'.
USE [YourDatabaseNameHere]
GO
ALTER DATABASE [YourDatabaseNameHere] SET RECOVERY SIMPLE
GO
Third,issue a checkpoint against the database to write the records from the transaction log to the database.
USE [YourDatabaseNameHere]
GO
CHECKPOINT
GO
Fourth,truncate the transaction log.
USE [YourDatabaseNameHere]
GO
BACKUP LOG [YourDatabaseNameHere] WITH NO_LOG
GO
Fifth,record the logical file name for the transaction log to use in the next step.
USE [YourDatabaseNameHere]
GO
SELECT Name
FROM sysfiles
WHERE name LIKE '%LOG%'
GO
Sixth,to free the unused space in your transaction log and return the space back to the operating system,shrink the transaction log file.
USE [YourDatabaseNameHere]
GO
DBCC SHRINKFILE ([FileNameFromPrevIoUsstep],[NeededFileSize])
GO
Seven,review the database transaction log size to verify it has been reduced.
USE [YourDatabaseNameHere]
GO
SELECT *
FROM sysfiles
WHERE name LIKE '%LOG%'
GO
Next Steps
- Review your key sql Server databases to determine if the transaction log growth is out of control.
- Review this code and modify it for one of your databases.
- Once the scripts are modified,test the scripts in a test environment to ensure they meet your needs.
- Schedule time to shrink your databases and communicate the configuration changes.
- Continue to monitor the database sizes and the available disk space on your servers.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。