How to get the logical name of the transaction log in SQL Server 2005

Viewed 53610

I am trying to write a T-SQL routine that shrink the transaction log file using DBCC SHRINKFILE based on the logical name of the database. The DB_NAME() function gives you the logical name of the database. Is there an equivalent one for the transaction log? If not, is there some other way to get this information? The default name for the transaction logs is <<Database Name>>_log, but I would rather not rely on this.

4 Answers
DECLARE @command varchar(1000) 
SELECT @command = 'USE [?] DBCC SHRINKFILE (2 , 0, TRUNCATEONLY)' 
EXEC sp_MSforeachdb @command 

--OR simply

EXEC sp_MSforeachdb 'USE [?] DBCC SHRINKFILE (2 , 0, TRUNCATEONLY)' 
Related