Monday, November 15, 2010

Delete Data or Log Files from a Database (SQL Server Management Studio) – 2008


============================================================
If you have to truncate a log in SQL 2008, this procedure should work
============================================================
============================================================
find those databases which do not use simple mode
============================================================
Select name,recovery_model_desc from
sys.databases

where recovery_model_desc <>
'SIMPLE'

GO
===========================================================
set your database to use simple mode
============================================================
ALTER
DATABASE YourDatabase SET
RECOVERY
SIMPLE
WITH NO_WAIT

GO
============================================================
truncate the log file
==============================================================
Use YourDatabase
GO
Declare @LogFileLogicalName sysname
select @LogFileLogicalName=Name from
sys.database_files
where
Type=1

print @LogFileLogicalName
DBCC Shrinkfile(@LogFileLogicalName,1)