# SQL Schema Extractor

Parse CREATE TABLE and ALTER TABLE statements from a SQL dump into a clean table, column, and constraint model as JSON or Markdown — locally in your browser.

## Run it

- **CLI:** `gizza tool sql-schema-extractor "CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  email VARCHAR(255) NOT NULL UNIQUE,
  age INT DEFAULT 0 CHECK (age >= 0)
);"`
- **Web:** https://gizza.ai/tools/sql-schema-extractor/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/sql-schema-extractor/tool.json

## Inputs

- `sql` — SQL dump / DDL _(field)_
- `output` — Output format _(field)_
- `dialect` — SQL dialect _(field)_
- `apply_alter` — Apply ALTER TABLE statements _(field)_
- `include_indexes` — Include indexes _(field)_

## Output

- Extracted schema (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `sql` — SQL dump / DDL
- `output` — Output format
- `dialect` — SQL dialect
- `apply_alter` — Apply ALTER TABLE statements
- `include_indexes` — Include indexes

Example: `https://gizza.ai/tools/sql-schema-extractor/?sql=CREATE%20TABLE%20users%20%28%0A%20%20id%20INT%20PRIMARY%20KEY%20AUTO_INCREMENT%2C%0A%20%20email%20VARCHAR%28255%29%20NOT%20NULL%20UNIQUE%2C%0A%20%20age%20INT%20DEFAULT%200%20CHECK%20%28age%20%3E%3D%200%29%0A%29%3B&output=json&dialect=auto&apply_alter=true&include_indexes=true`

---

## About this tool

SQL Schema Extractor turns raw DDL from a dump into a clean schema model without connecting to a database or executing anything. Paste `CREATE TABLE`, `ALTER TABLE`, and `CREATE INDEX` statements and it extracts tables, columns, types, nullability, defaults, primary keys, foreign keys, unique constraints, checks, and indexes.

Use JSON when you want structured data for automation, audits, migrations, or documentation pipelines. Use Markdown when you want a readable schema reference with one section per table. Comments and data rows are ignored, so mixed dumps that include `INSERT` statements still produce a schema-only result.

The parser is intentionally lenient and local-first. It normalizes common identifier quoting styles from MySQL, PostgreSQL, SQLite, SQL Server, and generic SQL, then folds supported `ALTER TABLE ... ADD` statements onto their target table by default so the output represents the final schema.

## FAQ

<details>
<summary>Does this execute my SQL or connect to a database?</summary>

No. The tool is a text parser that runs locally in the browser/CLI. It reads DDL text and emits a model; it does not connect to a database, run queries, create tables, or inspect live data.

</details>

<details>
<summary>Which SQL statements are parsed?</summary>

It focuses on schema-defining statements: `CREATE TABLE`, supported `ALTER TABLE ... ADD` forms, and `CREATE INDEX` / `CREATE UNIQUE INDEX`. Non-DDL statements such as `INSERT`, `UPDATE`, `SELECT`, `DROP`, and comments are skipped so dump files remain usable.

</details>

<details>
<summary>What output format should I choose?</summary>

Choose `json` for automation: it includes table counts, columns, constraints, foreign keys, checks, and indexes in a structured model. Choose `markdown` when you want a human-readable schema document with table sections and constraint lists.

</details>

<details>
<summary>Does it support every SQL dialect feature?</summary>

No. It covers common DDL patterns across MySQL, PostgreSQL, SQLite, SQL Server, and generic SQL, including quoted identifiers and common column/constraint syntax. It does not try to be a full SQL engine, parse stored procedures, infer relationships without explicit foreign keys, or render ER diagrams.

</details>

## Related tools

- [Adjacency Matrix Converter](https://gizza.ai/tools/adjacency-matrix-converter/): Convert a graph between edge list, adjacency matrix, and incidence matrix — directed or undirected, weighted or not. Free, private, runs in your browser.
- [Amazon Order Analyzer](https://gizza.ai/tools/amazon-order-analyzer/): Paste an Amazon order-history CSV export to summarize total spend by month, top items, and category breakdowns. Browser-only, private, with Markdown or JSON output.
- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
- [Reconcile bank statement and ledger CSVs](https://gizza.ai/tools/bank-statement-reconcile/): Match bank-statement CSV rows to ledger rows by date, signed amount, and fuzzy memo similarity, with unmatched and suggested matches.
- [Base64 ⇄ Base64url Converter](https://gizza.ai/tools/base64url-converter/): Convert standard Base64 to URL-safe Base64url and back in your browser — swaps +/ for -_, handles = padding, auto-detects direction. Free, private, no sign-up.
