All tools
Free · Private · No upload

Convert HTML Table to SQL Online

Turn an HTML table into SQL CREATE TABLE and INSERT statements. The markup is read in your browser and never uploaded.

Drop a CSV or Excel file here

CSV · XLSX · XLS · XLSM · XLSB

or paste your data below

How to convert an HTML table to SQL

Three steps from products.html to a .sql script.

1. Paste the HTML

Paste markup that contains a <table>, or drop an .html file.

2. Check it in the grid

Remove symbols that stop a column from being numeric, like the $ in $24.00. Otherwise Price becomes a TEXT column.

3. Set dialect and table

Pick the dialect, type a table name, tick CREATE TABLE or DROP TABLE IF EXISTS, then copy or download data.sql.

Example: HTML in, SQL out

A product table with a link in one cell, an &amp; entity, currency symbols and an empty cell.

products.html
<table>
  <tr><th>Product</th><th>Price</th><th>In stock</th></tr>
  <tr><td><a href="/p/1">Desk lamp</a></td><td>$24.00</td><td>Yes</td></tr>
  <tr><td>Chair &amp; cushion</td><td>$89.50</td><td></td></tr>
</table>
data.sql (MySQL, table "products")
CREATE TABLE `products` (
  `Product` TEXT,
  `Price` TEXT,
  `In_stock` TEXT
);

INSERT INTO `products` (`Product`, `Price`, `In_stock`) VALUES
('Desk lamp', '$24.00', 'Yes'),
('Chair & cushion', '$89.50', NULL);

The header "In stock" becomes the column `In_stock`, and the chair's empty cell is inserted as NULL.

What changes between HTML and SQL

Column types are guessed

In this example Product, Price and In_stock are TEXT. The rule: whole numbers give INT, a decimal point gives DOUBLE, anything else TEXT, dates included (other dialects use their own names, such as INTEGER and REAL).

Column names

Headers are turned into safe identifiers: characters other than letters, digits and _ become _, so "In stock" becomes In_stock. A header starting with a digit gets a col_ prefix, and duplicates get _2, _3.

Values

The first row is inserted as ('Desk lamp', '$24.00', 'Yes'): numbers bare, text in single quotes. The empty In stock for Chair & cushion becomes NULL.

Text content only

Each cell's text is taken, trimmed. Tags inside cells (<a> here) are dropped and entities are decoded, so &amp; arrive as the characters they stand for.

When to convert HTML to SQL

HTML to SQL in JavaScript

TabularJS reads HTML: every <table> becomes a worksheet. Then one INSERT is built, with the same quoting rules as this page.

import tabularjs from 'tabularjs';

// The first row of the table becomes the column titles
const { worksheets } = await tabularjs('products.html', { tableIndex: 0 });
const ENT = { amp: '&' }; // Node.js keeps entities as written
const decode = (v) => String(v ?? '').replace(/&(\w+);/g, (m, e) => ENT[e] ?? m);
const header = worksheets[0].columns.map((col) => decode(col.title));
const rows = worksheets[0].data.map((row) => row.map(decode));

const id = (name) => '`' + String(name).trim().replace(/[^A-Za-z0-9_]/g, '_') + '`';
const value = (v) => {
  if (v == null || String(v).trim() === '') return 'NULL';
  return isNaN(v) ? `'${String(v).replace(/'/g, "''")}'` : String(v).trim();
};
console.log(`INSERT INTO ${id('products')} (${header.map(id).join(', ')}) VALUES\n` +
  rows.map((row) => `(${header.map((_, i) => value(row[i])).join(', ')})`).join(',\n') + ';');

TabularJS differs from this page in two ways: it returns every <table> as a worksheet, and it turns colspan into mergeCells. In Node.js it leaves entities such as &amp; as written, hence the decode step.

npm install tabularjs MIT licensed

Frequently asked questions

Which row is used for the column names?

The first row of the table, whether its cells are <th> or <td>. If the table has no header row, untick First row as header and the columns are named col_1, col_2 and so on.

Can the currency symbols be stripped automatically?

No. Remove the $ in the grid; once Price holds plain numbers like 24.00, the CREATE TABLE gives it DOUBLE.

What about tables built with <div>s?

They can't be read. The converter needs real <table>, <tr>, <th> and <td> elements. For CSS grid or div layouts, copy the text and paste it as CSV instead.

Can I get one INSERT per row?

Not on this page: all rows go into one multi-row INSERT, which every listed database accepts and which runs faster. If a tool needs one statement per row, split the VALUES list in code.

Does products.html get uploaded when I convert it to SQL?

No. The markup is read in your browser and never uploaded.