Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import database (SQL file) in SQL Server Management Studio

I've created the structure of my database first in PhpMyAdmin and exported it to a .sql file. Now I'm looking everywhere in SQL Server Management Studio where I can import/add the data in a new database.

Does anybody where to look or what to click? I'm using the 2014 version (CTP2)

like image 369
Matt Avatar asked Mar 18 '14 19:03

Matt


People also ask

How do I open SQL file in SQL Server Management Studio?

You can open a document in one or more editors by clicking Open on the File menu and then clicking File. In the Open File dialog box, select the file, click the Open arrow, and then click Open With. In the Open With dialog box, in the Select a program to open list, click the preferred program, and then click Open.


1 Answers

If you have a .sql file which contains SQL statements, you can just copy and paste the contents (or open the file in a query window) and run it. This assumes it has all of the create table etc. statements to create the schema/structure and not just insert statements for the data.

Check the top of the file to make sure that it is first selecting the correct database, if not add a USE statement to select the correct database.

You didn't say how big the file was, but if it is quite large and has the insert statements (data as well as schema), then you'll probably want to run by CLI using sqlcmd command. Much faster and SSMS won't freak out.

Another alternative option to running the .sql file/code is to set up a data source for mysql and just use odbc to access the database itself.

Bear in mind that there are real and very annoying differences between mysql and t-sql that can make migration a pain. If you're just creating a few tables, it may not be an issue, but if there are a ton of tables with lots of fields of different data types, you may run into issues.

like image 164
a lead alcove Avatar answered Oct 21 '22 21:10

a lead alcove