Sunday, January 4, 2015

delete additional log files



Delete Additional Logfiles

If you restore a database to a secondary location and wants to delete extra log files which are not needed anyway then use the below script

USE <ENTER DATBASE NAME>

GO



SELECT 
'ALTER DATABASE ['+DB_NAME()+'] set recovery simple
GO
dbcc shrinkfile('+name +',EMPTYFILE)
GO
alter database ['+DB_NAME()+'] remove file '+NAME +'
go'

FROM SYS.database_files WHERE type_desc = 'LOG'
and file_id >
(SELECT min(file_id)FROM SYS.database_files WHERE type_desc = 'LOG')


Post a Comment

Featured Post

SQL Server AWS Migration BCP

stored procedure to generate BCP scritps to migrate the SQL Server database. Developed this stored procedure on my labs to simulate the Mi...

Contributors