Link to home
Start Free TrialLog in
Avatar of axnst2
axnst2Flag for United States of America

asked on

DBCC SHRINKEFILE has no effect

Hi Experts,

     I am trying to create a script to shrink the log file of a database to 1 MB.  The below script runs without errors but does not change the size of the log file!  Any thoughts as to why?  I am working with SQL Server 2008R2 (EXPRESS)!

DECLARE @LogFileTable AS TABLE (logicalName nvarchar(max), fileID int, DBFileName nvarchar(max), DBFileGroup nvarchar(max),
								size nvarchar(max), maxsize nvarchar(max), growth nvarchar(max), usage nvarchar(max))
 
INSERT INTO @LogFileTable EXEC sp_helpfile
 
DECLARE @DB_Name AS nvarchar(max),
		@DB_Log_FileName AS nvarchar(max);
 
SET @DB_Name='MyTestDB'

SET @DB_Log_FileName = (SELECT logicalName FROM @LogFileTable WHERE [usage] = 'log only')

EXEC  
('USE [' + @DB_Name + ']; ' + 
'DBCC SHRINKFILE( '''+@DB_Log_FileName+''', 1)' 
) 

Open in new window


Thanks!
ASKER CERTIFIED SOLUTION
Avatar of axnst2
axnst2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial