# How to Generate SQL INSERT Statements from the Exercises Dataset: A Complete Browser-Based Guide

> Generate SQL INSERT statements from the exercises dataset using a browser-based tool. Create dialect-specific scripts for SQL Server PostgreSQL MySQL and SQLite effortlessly.

- Repository: [Hasan Emir Yıldırım/exercises-dataset](https://github.com/hasaneyldrm/exercises-dataset)
- Tags: how-to-guide
- Published: 2026-07-31

---

**You can generate SQL INSERT statements from the exercises dataset using the browser-based [`setup.html`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/setup.html) tool, which creates dialect-specific scripts for SQL Server, PostgreSQL, MySQL, and SQLite without any server-side processing.**

The `hasaneyldrm/exercises-dataset` repository provides a client-side solution for converting 1,324 JSON exercise records into ready-to-run SQL scripts. This approach keeps all data processing local to your machine, ensuring privacy while supporting multiple database dialects through a single interactive interface.

## Opening the Interactive Setup Guide

Start by opening [`setup.html`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/setup.html) located in the repository root. You can launch this file directly in any modern browser using the local file protocol (`file:///path/to/exercises-dataset/setup.html`) or view it via GitHub Pages if enabled. This HTML document serves as a self-contained developer tool that requires no build step, dependencies, or internet connectivity beyond loading the initial JSON data.

## Selecting Your Database Engine

The interface presents a tabbed navigation system that stores your selection in a JavaScript variable named `currentDb`. Each tab corresponds to a specific SQL dialect:

- **SQL Server** (`mssql`)
- **PostgreSQL** (`postgresql`)
- **MySQL** (`mysql`)
- **SQLite** (`sqlite`)

Selecting a tab updates the `currentDb` variable, which controls both the `CREATE TABLE` syntax displayed and the format of the generated INSERT statements. The HTML structure for this selector appears at the top of the document:

```html
<div class="tab-bar" id="db-tabs">
  <button class="tab-btn active" data-db="mssql">SQL Server</button>
  <button class="tab-btn" data-db="postgresql">PostgreSQL</button>
  <button class="tab-btn" data-db="mysql">MySQL</button>
  <button class="tab-btn" data-db="sqlite">SQLite</button>
</div>

```

## Creating the Table Structure

Before generating INSERT statements, you must create the target table using the dialect-specific template provided in the `DB_SQL` object. Located at lines 379-415 in [`setup.html`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/setup.html), this object contains properly typed `CREATE TABLE` statements for each supported engine:

```javascript
const DB_SQL = {
  mssql: `CREATE TABLE exercises ( ... );`,
  postgresql: `CREATE TABLE exercises ( ... );`,
  mysql: `CREATE TABLE exercises ( ... );`,
  sqlite: `CREATE TABLE exercises ( ... );`
};

```

Copy the SQL block from your selected tab and execute it in your database client. This creates the `exercises` table with columns matching the JSON structure, including proper data types for IDs, names, categories, and timestamps.

## Generating the INSERT Statements

Click the **Generate INSERT SQL** button (element ID `generate-sql-btn`) to trigger the `generateInsertSql` function defined around lines 1550-1585. This async function performs the following operations:

1. Fetches [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json) containing the full dataset
2. Iterates through all 1,324 records
3. Escapes single quotes in string values to prevent SQL injection
4. Formats values according to the selected dialect's requirements
5. Constructs complete `INSERT INTO exercises VALUES (...)` statements
6. Packages the output as a downloadable file

The core generation logic handles value serialization safely:

```javascript
async function generateInsertSql() {
  generateBtn.disabled = true;
  generateStatus.textContent = 'Loading exercise data…';
  const res = await fetch('data/exercises.json');
  const exercises = await res.json();

  generateStatus.textContent = 'Generating…';
  const rows = exercises.map(e => {
    const values = [
      `'${e.id}'`,
      `'${e.name.replace(/'/g, "''")}'`,
      `'${e.category}'`,
      `'${e.created_at}'`
    ].join(', ');
    return `INSERT INTO exercises VALUES (${values});`;
  }).join('\n');

  const blob = new Blob([rows], { type: 'application/sql' });
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = `exercises_insert_${currentDb}.sql`;
  a.click();
}

```

The function produces a file named `exercises_insert_<db>.sql` (where `<db>` represents your selected engine) containing the complete import script.

## Importing the Generated Script

With the SQL file downloaded, import the data using your database's standard command-line tool or GUI client:

- **PostgreSQL**: `psql -d your_database -f exercises_insert_postgresql.sql`
- **MySQL**: `mysql -u user -p database_name < exercises_insert_mysql.sql`
- **SQLite**: `sqlite3 database.db < exercises_insert_sqlite.sql`
- **SQL Server**: `sqlcmd -S server -d database -i exercises_insert_mssql.sql`

## Summary

- **Browser-based generation**: The [`setup.html`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/setup.html) file in `hasaneyldrm/exercises-dataset` provides a zero-dependency tool that runs entirely client-side.
- **Multi-dialect support**: The `DB_SQL` object (lines 379-415) and `currentDb` variable ensure correct syntax for SQL Server, PostgreSQL, MySQL, and SQLite.
- **Complete dataset coverage**: The `generateInsertSql` function (lines 1550-1585) processes all 1,324 records from [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json).
- **Safe string handling**: Single quotes in exercise names are escaped automatically to produce valid SQL syntax.
- **Immediate usability**: Output files follow the naming convention `exercises_insert_<db>.sql` and work with standard database clients.

## Frequently Asked Questions

### Can I generate SQL INSERT statements without installing any software?

Yes. The [`setup.html`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/setup.html) file operates entirely within your browser. You only need a modern web browser to load the file and generate the SQL scripts—no Node.js, Python, or database drivers are required for the generation step.

### How does the tool handle special characters in exercise names?

The `generateInsertSql` function applies a regular expression replacement (`replace(/'/g, "''")`) to escape single quotes within string values. This prevents SQL syntax errors and injection issues when exercise names contain apostrophes.

### Is there a limit to how many records the generator can handle?

The repository ships with 1,324 exercises in [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json), and the generator processes the entire array client-side. Since modern browsers can handle JSON parsing and string manipulation for datasets of this size efficiently, you should experience no performance issues with the current dataset.

### Can I modify the table schema before generating the INSERT statements?

You must modify the `DB_SQL` object at lines 379-415 in [`setup.html`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/setup.html) if you want to change column definitions. However, the generated INSERT statements assume the standard schema; altering the table structure requires corresponding changes to the value mapping logic in the `generateInsertSql` function around lines 1550-1585.