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?
.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.
One could use a simple SQLLite-browser with an IMPORT feature. This may be the easiest way if you're not into learning SQL.
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.
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/
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!
Can't speak to opening it as a table, but if you are interested in reviewing the SQL code you can simply change the extension to .txt and open with a text editor.
protected by slhck Aug 22 at 14:31
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?