Convert Markdown to SQL Online
Turn a Markdown table into SQL: a CREATE TABLE and INSERT statements. The table is read in your browser and never uploaded.
Drop a CSV or Excel file here
CSV · XLSX · XLS · XLSM · XLSB
Ready to download as a binary file.
How to convert a Markdown table to SQL
Three steps from errors.md to a .sql script.
1. Paste the table
Paste a Markdown pipe table or drop a .md file.
2. Check it in the grid
Look at columns that should be booleans: retry holds yes and no, so it becomes TEXT. Change the type in the CREATE TABLE if you need BOOLEAN.
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: Markdown in, SQL out
A table of API error codes from the docs, with a numeric code column.
| code | name | retry |
| ---: | ----------------- | ----- |
| 404 | Not Found | no |
| 429 | Too Many Requests | yes |CREATE TABLE `errors` (
`code` INT,
`name` TEXT,
`retry` TEXT
);
INSERT INTO `errors` (`code`, `name`, `retry`) VALUES
(404, 'Not Found', 'no'),
(429, 'Too Many Requests', 'yes');code holds only whole numbers, so it becomes INT and is inserted without quotes; name and retry are TEXT.
What changes between Markdown and SQL
Column types are guessed
In this example code is INT, name and retry 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).
Values
The first row is inserted as (404, 'Not Found', 'no'): numbers bare, text in single quotes.
One INSERT for all rows
All rows go into a single multi-row INSERT. SQL Server accepts at most 1,000 rows per VALUES list, so split larger scripts there. Identifiers are quoted per dialect: `backticks` for MySQL, "double quotes" for PostgreSQL and SQLite, [brackets] for SQL Server.
Header and separator
The row above the separator line becomes the header (code, name and retry). The separator is dropped, along with its alignment colons.
When to convert Markdown to SQL
- Loading reference data written in docs (plans, limits, error codes) into a database.
- Turning a spec table into seed data for development.
Markdown to SQL in JavaScript
A pipe table is easy to split by hand. Then one INSERT is built, with the same quoting rules as this page.
import { readFile } from 'node:fs/promises';
const lines = (await readFile('errors.md', 'utf8')).split('\n').filter((l) => l.includes('|'));
const cells = (line) => line.trim().replace(/^\||\|$/g, '')
.split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, '|'));
const header = cells(lines[0]);
const rows = lines.slice(2).map(cells); // lines[1] is the separator
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('errors')} (${header.map(id).join(', ')}) VALUES\n` +
rows.map((row) => `(${header.map((_, i) => value(row[i])).join(', ')})`).join(',\n') + ';');Like this page, the split skips the separator line and honours escaped pipes.
Frequently asked questions
Does the table name come from the Markdown?
No. Markdown tables have no name, so type one in the Table box. The default is my_table; the example uses errors.
Can I run the script on SQLite?
Yes. Pick SQLite: identifiers are double-quoted and the types are INTEGER, REAL and TEXT. Paste the script into the sqlite3 shell or any client.
What counts as a Markdown table?
A header row, a separator row made of dashes (with optional colons) and data rows, separated by |. The pipes at the start and end of each line are optional.
Does the CREATE TABLE add a primary key?
No. It lists the columns with their guessed types and nothing else: no primary key, NOT NULL or indexes. Add them before running the script if the table is going to stay.
Does errors.md get uploaded when I convert it to SQL?
No. The table is read in your browser and never uploaded.