0

I have a problem in importing a database script in SQL Server 2012 Management Studio however, I successfully exported the schema and data. In exporting the database, I have done the steps:

  1. Right click on the database under Tasks;
  2. Click generate scripts and follow the wizard;
  3. Advance option: Types of data to script = Schema and data
  4. Finished

However, when I open the file and transfer it in an empty database (execute the script.sql) using SQL Server Management Studio, I can't import it. On SQL Server 2008 I can easily do that thing but on SQL Server 2012, I think there is something wrong on it.

Here is the screenshot.

enter image description here

And when I try to execute the script.sql file on the new Copy of database (db_Copy), There is an error message below. ''

enter image description here

Please help me on this issue, Have I done something wrong in exporting my data (Generate script)? Or It can be on SQL Server I'm using? I am using SQL Server 2012 Express.

Please help me, All i want to do is to my database to another database using the generated scripts.

Thanks in advance.

EDIT: What is the proper way to import the generated scripts on the empty database?

2
  • What about the error isn't clear to you? That database db_Dasureco you're trying to create in the SQL script already exists on this SQL Server instance. Either don't try to create it again, or use a different database name ...... Commented Feb 4, 2014 at 6:19
  • Yes. I tried to change the database name, ex. CREATE DATABASE [db_NewCopyDatabase] , but it didn't execute. I executed the script then it takes 10 mins now of running the script. Is it normal? Commented Feb 4, 2014 at 6:33

2 Answers 2

2

Create an empty database or if you have one already target that one.

Open CMD with elevated privilege and run:

sqlcmd -S SERVERNAME -d MYDATABASE -U USERNAME -P PASSWORD -i C:\path\mysqlfile.sql -o C:\path\results.txt

basically:

  • -S: is your servername or localhost
  • -d: is the database you are targeting
  • -U: is the username
  • -P: is the password
  • -i: is the path to your .sql file
  • -o: is where the logs file will be saved so if you had problem during the importation you can debug them
Sign up to request clarification or add additional context in comments.

Comments

0

Replace [db_Dasureco] for [db_NewCopyDatabase] not only in CREATE DATABASE, but everywhere you see [db_Dasureco].

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.