How to convert html tables to sql files

I know why you’re here, you want to convert a table such as the one below into full-fledged database table which can be manipulated using queries.

image

The image above is from w3schools of course.

Requirements

  • phpmyadmin / heidisql
  • Microsoft Excel or any spreadsheet application

 

Procedure

Converting an html table into an sql file can be done in 3 steps. First you need to have a source. Where are you getting the data from? In this case we are getting it from the fruits tables at w3schools. Highlight the whole table and paste it on Microsoft Excel, just right-click on the first cell of the sheet and select paste(Match Destination Formatting). After that, go ahead and save the file as an excel 2003 file(xls) or excel 2007 file(xlsx). Finally you just have to import the excel file using phpmyadmin or heidisql. Once you’re done you’ll end up with this.

image

Just remember that the name of the table depends on the name of the sheet. Sheet1 is the default so you have to rename the sheet if you’re planning to import multiple excel files on a single database. But you can just import it all at once, just use a different sheet for a different table structure.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s