{
  "slug": "er-diagram-from-sql",
  "name": "gizza-ai/er-diagram-from-sql",
  "version": "0.1.0",
  "title": "ER Diagram from SQL — CREATE TABLE DDL to Mermaid erDiagram — gizza.ai",
  "description": "Paste SQL CREATE TABLE / ALTER TABLE DDL and get Mermaid erDiagram code with entities, typed columns, PK/FK/UK markers, and crow's-foot relationships.",
  "tags": [
    "er diagram from sql",
    "sql to mermaid",
    "sql to erd",
    "mermaid erdiagram generator",
    "create table to diagram",
    "database schema diagram",
    "ddl to er diagram",
    "entity relationship diagram generator",
    "sql schema visualizer"
  ],
  "category": "developer",
  "urls": {
    "page": "https://gizza.ai/tools/er-diagram-from-sql/",
    "markdown": "https://gizza.ai/tools/er-diagram-from-sql/index.md",
    "descriptor": "https://gizza.ai/tools/er-diagram-from-sql/tool.json",
    "deep_link_example": "https://gizza.ai/tools/er-diagram-from-sql/?sql=CREATE%20TABLE%20users%20%28%0A%20%20id%20INT%20PRIMARY%20KEY%2C%0A%20%20email%20VARCHAR%28255%29%20NOT%20NULL%20UNIQUE%0A%29%3B%0ACREATE%20TABLE%20orders%20%28%0A%20%20id%20INT%20PRIMARY%20KEY%2C%0A%20%20user_id%20INT%20NOT%20NULL%20REFERENCES%20users%28id%29%2C%0A%20%20total%20DECIMAL%2810%2C2%29%0A%29%3B&dialect=auto&attributes=all&key_markers=true&mark_nullable=true&infer_relations=true&relationship_label=column&direction=auto&fence=true"
  },
  "cli": "gizza tool er-diagram-from-sql \"CREATE TABLE users (\n  id INT PRIMARY KEY,\n  email VARCHAR(255) NOT NULL UNIQUE\n);\nCREATE TABLE orders (\n  id INT PRIMARY KEY,\n  user_id INT NOT NULL REFERENCES users(id),\n  total DECIMAL(10,2)\n);\"",
  "tool": {
    "description": "Turn SQL DDL into a Mermaid ER diagram. Paste CREATE TABLE statements (ALTER TABLE ... ADD FOREIGN KEY and CREATE UNIQUE INDEX are folded in) and it emits erDiagram source: one entity per table, its columns as 'TYPE name' attributes with PK / FK / UK markers, and one crow's-foot relationship per foreign key. Cardinality is derived from the schema — the parent side is '||' (exactly one) when every FK column is NOT NULL and '|o' (zero or one) otherwise; the child side is 'o{' (zero or more), or 'o|' when the FK columns are themselves unique in the child (a 1:1); the line is solid '--' for a NOT NULL FK and dashed '..' for a nullable one. Options: limit attributes to keys only or hide them entirely for wide schemas, toggle the PK/FK/UK markers, mark nullable columns with Mermaid's 'TYPE?' form, infer relationships from '<table>_id' columns that lack a foreign key, label relationships by column or by constraint name (or not at all), set a layout direction, and wrap the result in a ```mermaid code fence. Types and identifiers are sanitized to Mermaid-safe tokens (DECIMAL(10,2) becomes DECIMAL(10_2), TIMESTAMP WITH TIME ZONE becomes TIMESTAMP_WITH_TIME_ZONE) so the diagram actually renders. Supports MySQL, PostgreSQL, SQLite, SQL Server and generic dialects. It is a lenient text parser, not a SQL engine: comments and non-DDL statements are skipped and nothing is executed. It emits diagram source, not an image; paste it anywhere Mermaid renders. Maximum 500 tables.",
    "parameters": {
      "additionalProperties": false,
      "properties": {
        "attributes": {
          "default": "all",
          "description": "Which columns to list inside each entity block. 'all' (default) lists every column as 'TYPE name'. 'keys' keeps only primary-key, foreign-key and unique columns, which keeps a wide schema readable. 'none' emits bare entity names plus the relationship lines only. Default all.",
          "enum": [
            "all",
            "keys",
            "none"
          ],
          "type": "string"
        },
        "dialect": {
          "default": "auto",
          "description": "SQL dialect hint. Identifiers are normalized for every dialect (backticks, \"double quotes\" and [brackets] are stripped); this mainly controls whether '#' starts a line comment (mysql/auto). Default auto.",
          "enum": [
            "auto",
            "mysql",
            "postgres",
            "sqlite",
            "mssql",
            "generic"
          ],
          "type": "string"
        },
        "direction": {
          "default": "auto",
          "description": "Layout direction emitted as a 'direction' statement inside the diagram: LR (left to right), RL, TB (top to bottom, TD is accepted as an alias) or BT. 'auto' (default) omits the statement and lets the renderer choose. Default auto.",
          "enum": [
            "auto",
            "LR",
            "RL",
            "TB",
            "BT"
          ],
          "type": "string"
        },
        "fence": {
          "default": false,
          "description": "Wrap the diagram in a ```mermaid code fence so it can be pasted straight into a Markdown file, a GitHub issue or a pull-request comment. Default false (bare diagram source).",
          "type": "boolean"
        },
        "infer_relations": {
          "default": false,
          "description": "Also draw a relationship for a '<name>_id' column that has no explicit FOREIGN KEY, when '<name>' (or its plural) matches a table in the same DDL — useful for schemas that enforce references in the application instead of the database. Never duplicates an explicit foreign key. Default false.",
          "type": "boolean"
        },
        "key_markers": {
          "default": true,
          "description": "Append Mermaid's PK / FK / UK markers to attribute lines (e.g. 'INT user_id FK'). UK is only added for single-column uniqueness, since a member of a composite UNIQUE is not unique on its own. Ignored when attributes is 'none'. Default true.",
          "type": "boolean"
        },
        "mark_nullable": {
          "default": false,
          "description": "Render nullable columns with Mermaid's optional-attribute form 'TYPE? name' so NULL-able columns are visible in the diagram. Default false.",
          "type": "boolean"
        },
        "relationship_label": {
          "default": "column",
          "description": "What to write after the ':' on each relationship line. 'column' (default) uses the foreign-key column name(s). 'constraint' uses the FOREIGN KEY constraint name, falling back to the columns when it is unnamed. 'none' emits an empty label, which keeps a busy diagram clean. Default column.",
          "enum": [
            "column",
            "constraint",
            "none"
          ],
          "type": "string"
        },
        "sql": {
          "description": "The SQL DDL to diagram. Include one or more CREATE TABLE statements (ALTER TABLE ... ADD FOREIGN KEY and CREATE UNIQUE INDEX are folded in) — e.g. \"CREATE TABLE users (id INT PRIMARY KEY); CREATE TABLE orders (id INT PRIMARY KEY, user_id INT NOT NULL REFERENCES users(id));\". Comments and non-DDL statements (INSERT, SELECT, ...) are ignored and nothing is executed. Maximum 500 tables.",
          "type": "string"
        }
      },
      "required": [
        "sql"
      ],
      "type": "object"
    }
  }
}