SQL Server 2008-2014

USE UserDB;

GO

DBCC SHRINKFILE (DataFile1, 7);

GO

or

DBCC SHRINKFILE ( { file_name | file_id } { [ , EMPTYFILE ] | [ [ , target_size ] [ , { NOTRUNCATE | TRUNCATEONLY } ] ] } ) [ WITH NO_INFOMSGS ]

SQL Server 2005

SQLDatabase.TransactionLog.Truncate();

SQLDatabase.Shrink(5, SQLDMO.SQLDMO_SHRINK_TYPE.SQLDMOShrink_NoTruncate);

SQLDatabase.TransactionLog.Truncate();

SQLDatabase.Shrink(5, SQLDMO.SQLDMO_SHRINK_TYPE.SQLDMOShrink_Default);

USE [SQLdefragRepository]

GO

DBCC SHRINKFILE (N’SQLdefragRepository_log’ , 1000) — value in MB

GO