I'm trying to migrate my database to another server, an older version. Currently my database is on SQL Server 2014, but I need to add migrate it to SQL Server 2012 because that's the one my server has.

I installed both versions of the server (2012 and 2014) on my local machine. Created the script with the correct version (from the 2014 edition server, following "Tasks->Generate Scripts" with both schema and data, since my data is quite small in size), and now I'm trying to execute the script, but I got the following message:

Msg 5170, Level 16, State 1, Line 2
Cannot create file 'C:\Program Files....mdf' because it already exists. Change the file path or the file name, and retry the operation.

I understand the script is trying to create a database that already exists, so do I need to change the script?

  • My answer dba.stackexchange.com/a/55063/8783 will help you. You should just bcp out the data and bcp in on the old version. There are certain cavets, just read my answer and if you have any question, will help out.
    – Kin Shah
    Dec 17, 2018 at 2:38

1 Answer 1


The script generated will have the data folder for your 2014 instance. Since the database already exists on the 2014 instance, and the files are already there, the CREATE DATABASE statement will fail.

Change the path in the CREATE DATABASE statement to the 2012 data folder.

  • Created a database with the same name and run the script, but I got this error:Msg 1801, Level 16, State 3, Line 2 Database 'DB' already exists. Choose a different database name. But it looks like some of the data are on the database after the script was run. Is this normal? Thank you very much! Jun 16, 2016 at 8:04
  • 1
    If the database already exists in 2012, you will get that error (Or if you already ran the script and the DB got created). If so just drop it, or use a different name for the DB and it's files Jun 16, 2016 at 8:08
  • I tried to create a different name for the database, but I got the following error: Directory lookup for the file "C:\Program Files\....mdf" failed with the operating system error 3(The system cannot find the path specified.). So if it means I have to create a database beforehand, why does it have the previous error? Jun 16, 2016 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.