4

I'd like to import a database without knowing its name from a .sql file.

In MySql server it is easy because there is tools like heidSQL in which I can import easily my database from a sql file but in SQL Server I can't find the method to do it.

I tried to read the file in notepad but the encoding makes the content unreadable.

jj

When i execute this query RESTORE HEADERONLY FROM DISK = N'C:\Planning\bdd.sql' i have this hhh

  1. How can I do it with SQL server?
  2. Can SQL Server Management Studio do this task or do I have to install a new tool?

migrated from stackoverflow.com Jun 8 '13 at 7:26

This question came from our site for professional and enthusiast programmers.

  • 1
    How did you get this file? .sql are script files that should contain readable code which you can open and run from Management Studio. This does not look much usable. – Nenad Zivkovic Jun 7 '13 at 10:51
  • 4
    SQL Server backup files are usually named .bak and you can restore them with SSMS. However it is possible to name the file otherwise. Perhaps you can try restoring it and see if it's valid backup. Right click on Databases node in SSMS and choose Restore Database... – Nenad Zivkovic Jun 7 '13 at 10:54
  • 1
    Rename .sql file to .bak and try it again. – Devart Jun 7 '13 at 11:04
  • 2
    try running this Query: RESTORE HEADERONLY FROM DISK = N'C:\FileName.sql' replace correct path. – Vishal Gajjar Jun 7 '13 at 11:07
  • 1
    Yes, run the query proposed by @VishalGajjar. If it is a valid backup file you will receive info about what it contains. If not you'll get a red message saying it is incorrectly formed. – Nenad Zivkovic Jun 7 '13 at 11:22
4

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
2

Yes, you can do it with SQL Server Management Studio Here is the instructions how to ! http://technet.microsoft.com/library/Cc966390

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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