SQL Server Error 1060 Demystified: Why It Happens and How to Resolve It

August 27, 2025 by Andrew Smith

Error 1060 in SQL Server can be a puzzler, especially if you’re not a database wizard. But don’t worry! Let’s break it down in a fun and simple way. You’ll soon see that it’s not as scary as it sounds.

First things first… What is SQL Server Error 1060?

SQL Server Error 1060 usually pops up with a message like:

Cannot create file because it already exists.

Seems harmless, right? But when it stalls your work, it suddenly feels like a dragon.

So, why does it happen?

It happens when SQL Server tries to create a file, but a file with that name already exists in the location. Happens more often than you’d think. Let’s dive into the common reasons:

  • Duplicate file names during database creation or restoration.
  • Incorrect paths in the script or backup settings.
  • Manual file placement without checking what’s already there.

Think of a file like a notebook. If you already have one notebook called “Math2023” and you try to create another with the same name in the same shelf, that’s gonna cause confusion — or an error!

When exactly does Error 1060 appear?

Here are some common scenarios:

  • You’re restoring a database from a backup and forget to change file names.
  • You’re attaching a detached database that uses file names already taken by another database.
  • You try to create a database and it clashes with an existing MDF or LDF file in the Data directory.

Alright, how do we fix it?

Here are the steps to conquer Error 1060 and safely continue your work:

1. Check for Existing Files

Go to your SQL Server’s data directory and look for files with the same name you’re trying to use.

  • Open File Explorer.
  • Navigate to the folder (usually C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA).
  • See if the file already lives there.

2. Use a Different Name

If that file already exists and you don’t want to mess with it, just give your new database a unique name.

Example:

CREATE DATABASE Sales2024 
ON (NAME = SalesData, FILENAME = 'C:\Data\SalesNew.mdf'),
   (NAME = SalesLog, FILENAME = 'C:\Data\SalesNew_log.ldf')

3. Use the WITH MOVE Option During Restore

If you’re restoring from a backup, tell SQL Server where to create your files:

RESTORE DATABASE SalesCopy 
FROM DISK = 'D:\Backups\Sales.bak'
WITH MOVE 'SalesData' TO 'C:\Data\SalesCopy.mdf',
     MOVE 'SalesLog' TO 'C:\Data\SalesCopy_log.ldf'

This tells SQL Server, “Don’t use the old file path — use this new one I’m giving you.”

Image not found in postmeta

4. Delete Unused Files (Only If Safe!)

Warning: Be careful! Make sure the file isn’t used by another running database.

  • Stop SQL Server (if safe).
  • Delete the file manually if you’re sure it’s not needed.

5. Check Your Scripts

If you use automation or scripts to create databases, double-check the file paths before running them. It saves time and prevents surprise dragons (aka errors).

Best Practices to Avoid Error 1060

Let’s wrap it up with some pro tips so Error 1060 becomes history:

  • Always give unique names to each new database and its physical files.
  • Keep backups in a separate folder from your live data files.
  • Use variables in your scripts to create dynamic file naming.

In Conclusion

Error 1060 isn’t a villain — it’s more like a helpful guard saying, “Hey buddy, you already have a file named that. Want to name the new one something else?”

With a little care and naming creativity, you’ll never have to wrestle with it again.

Happy SQL-ing!