Monday , October 7 2024

CREATE DATABASE failed. Some file names listed could not be created.(Cannot create file ” because it already exists. )

 

ERROR MESAGGE:

CREATE DATABASE failed. Some file names listed could not be created. Check related errors. Cannot create file ‘C:\Program Files\Microsoft SQL Server\MSSQL.x\MSSQL\DATA\<file_name>’ because it already exists. Change the file path or the file name, and retry the operation. (Microsoft SQL Server, Error: 1802)”</file_name>

EXPLANATION:

You may experience this error when creating a database.

Consider the following scenario:

You have a database named “xxx”. By default, if you don’t specifically specify it, the data file name of this database is “xxx.mdf” and the name of the log file is “xxx_log.ldf”.

You want to create one more from the database named “xxx”, but you want to keep the one already created.

For this, you are changing the name of the old “xxx” database to “xxx_old”. But in this case, only the logical name of the database has changed. So the file names remain the same.

The name of the database that you are trying to create is “xxx”, so the file names are identical to the file names of the previously created “xxx” database, so you get errors.

SOLUTION:

If you are trying to create your database using SQL Server Management Studio, you can resolve this issue by specifying the file names yourself as you see below.

 

If you are creating your database with the CREATE DATABASE command, you can specify the file name as you see in the sample script below.

Loading

About Ekrem Önsoy

The original article was written in Turkish by Ekrem Önsoy and translated to English by dbtut with the consent of the author. The copyright of the article belongs to the author. The author shall not be liable in any way for any defect caused by translation.

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories