Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Someone gave me a file with extension sql, but I don't know what should I use to open it. I can open it with a text editor, but I would like to view it as a table. Is there any software that can do it without much effort? If not, do you know any quick recipe to do it?

share|improve this question

4 Answers 4

up vote 10 down vote accepted

.sql files are not tables per se. They're an exported database. Basically code for the database software to create the tables and such. CREATE TABLE, etc. The very same code you would use if you wanted to create a similar database/table(s).

This means the file is not a table, and the only thing that can make a table out of it is SQL software such as MySQL.

To compare, it's as if your friend sent you a macro/script that automatically creates a series of files, and you wanted to view the files without launching the macro and actually creating the files. Not really possible unless you have a very specific tool that emulates Windows creating files.

So I think your only solution is to install SQL and to import the database, effectively creating it anew on your own computer. To do this, I think the simplest way is to install and run WAMPserver ( http://www.wampserver.com/en/ ) , then to type "localhost" in your Web browser's address bar. Then you click phpMyAdmin, and click import to, well, import the file. Make sure the file encodings match.

Note that WAMP (and, therefore, MySQL) is probably only going to work if the file was exported in the MySQL format. That is, if the original database was in MySQL or if the other SQL engine (such as Microsoft SQL Server) has an option for exportation compatible with MySQL. And if the option was used, of course. If not, you'll need to find what database software's format the .sql file is in and install the appropriate software.

Oh, just before posting I did a quick search, and I think I might have found a tool that possibly allows you to simulate SQL and just view the table(s) without having to have the actual database. Maybe. Up to you to test it. Might not do what you want at all, but if it does, it might be simpler than WAMP. I'm sure installing the appropriate SQL software works, though.

http://www.digitalcoding.com/free-software/database/SQL-Preview-and-Export-Tool.html

share|improve this answer
3  
Note that SQL syntaxes differ slightly between database engines. In the simplest cases the same script will work across a number of engines, but as soon as you do anything non-trivial, you are going to run into various implementation-specific things. Take name quoting for example; MySQL uses backticks, whereas MS SQL and Access use square brackets. Some field names can be treated as reserved keywords in one database engine but be valid in another. So to be certain, you need to run the script in the same database engine software that was used to create it. Otherwise it may or may not work. –  Michael Kjörling Jan 8 '13 at 9:11
    
Yes uhm. Just that I figured that it would -probably- work this way, and/or that most people use MySQL anyway, to the best of my knowledge. And well, the OP doesn't seem to be so knowledgeable in this. I feel giving too much detail would've been, maybe, dizzying. :p –  Ariane Jan 8 '13 at 16:18
    
Good answer, just wanted to note that going by the name of the tool (Preview and Export) and its description ("First select the data provider from the dropdown menu. And provide the database connection string to connect to database."), it won't help in this case. –  Karan Jan 8 '13 at 17:05
    
The OP is hardly going to be helped when the database engine gives an error along the lines of invalid identifier or the likes. No need to go into every detail, but I do feel that it is important to note that different RDBMSs have different syntaxes. –  Michael Kjörling Jan 8 '13 at 20:03
1  
And depending on context, "most people" definitely do not use MySQL. For example, MySQL is reasonably common in Linux environments, but virtually unheard of in Windows hosting. –  Michael Kjörling Jan 8 '13 at 20:06

I just want to say thanks, almost a year later, to Ariane who's answer quickly resolved the same issue on my end. I was in an environment without internet and needed to convert a client's MySQL database table to .xls for a third party so I pulled the .SQL file from the database.

Since I know nothing of MySQL it was quite a chore for me to learn how to

mysql -uroot -ppassword

> show databases;
> use thisdatabase;
> show tables; 

then use mysqldump

/usr/bin/mysqldump -uroot -ppassword thisdatabase -e "thistable" > thistable.sql

But after reading the post above that suggested "to install and run WAMPserver ( http://www.wampserver.com/en/ ) , then to type "localhost" in your Web browser's address bar. Then you click phpMyAdmin, and click import to, well, import the file." It really was that simple.

After importing it into the installation created 'test' database, I was easily able to export an .xls file for opening in Excel.

However it should be noted that using the option "CSV for Excel" did not product a CSV format that Excel could use without making a mess but choosing basic "CSV" with options "Remove carriage return/line feed characters within columns" and "Put columns names in the first row" produced the perfect file.

I realize this is a year old but perhaps someone like me will come along in the future and this will help!

share|improve this answer

If your SQL file has schema definition i.e. create table blah and also insert statements to add data, you could use sqlfiddle: http://sqlfiddle.com/

share|improve this answer

The .sql file contains the SQL statements required to rebuild the database. The person who sent it to you has dumped either a portion or the full database to the .sql file.

Because you're asking this question, I think it's better if you get that person to export the data you want to view in a CSV (comma separated values) file so you can view in in tables in Excel.

The .sql file is good if you are a database admin yourself. You go to your database server and import the .sql file, and the database server will recreate the database as described in the .sql file sent to you.

You don't need a WAMP server, you only need the database server to import the SQL script. However, you'll save yourself a LOT of trouble by just asking the person to send you a CSV file, not an SQL dump.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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