Deleting a data or transaction log file removes the file from the database. You cannot remove a file from the database unless the file has no existing data or transaction log information; the file must be completely empty before it can be removed. To empty a data file by moving data from the data file to other files in the same filegroup, use the DBCC SHRINKFILE statement and specify the EMPTYFILE clause. Because the Database Engine no longer allows data to be placed on the file after the shrink operation, the empty file can be removed by using the ALTER DATABASE statement or SQL Server Management Studio.
You cannot move transaction log data from one log file to another to empty a transaction log file. To remove inactive transactions from a transaction log file, the transaction log must be truncated or backed up. When the transaction log file no longer contains any active or inactive transactions, the log file can be removed from the database. For more information, see Managing the Transaction Log.
Steps to Remove Data File
-- Empty the data file DBCC SHRINKFILE (Test1data, EMPTYFILE)
-- Backup the Database / Transaction Log so the file can be cleared out completely BACKUP DATABASE AdventureWorks2008R2 TO DISK = '\\backupshare\AdventureWorks2008R2.bak'
-- Backup the Database / Transaction Log so the file can be cleared out completely BACKUP LOG AdventureWorks2008R2 TO DISK = '\\backupshare\LOG_AdventureWorks2008R2_0600.bak'
-- Remove the data file from the database ALTER DATABASE AdventureWorks2008R2 REMOVE FILE Test1data