SQL Server databases store their data and objects in files. Each database has at least one data file (and a log file), but it’s not restricted to just one – it could have many data files. If you ever find yourself in the situation where you need to remove a data file from a database, you’ll need to empty that file first, before removing it.
But don’t worry, emptying a file doesn’t actually delete the data. It simply migrates the file’s data to other files within the same filegroup.
The examples below demonstrate how to empty a data file, then remove it from the database using Transact-SQL.