JSON 转 SQL CREATE TABLE 和 DDL

将 JSON 示例转换为 PostgreSQL、MySQL、SQLite、SQL Server 或 Oracle 的 SQL 建表语句草稿。

// about

工具介绍

工具会从 JSON 字段推断列和 SQL 类型并生成 DDL 草稿。嵌套值会表示为 JSON 或文本,生产使用前必须检查生成的脚本。

如何使用

  1. 将有代表性的 JSON 对象粘贴到输入框。
  2. 选择数据库并输入表名。
  3. 点击生成,然后检查类型、约束、索引和关系。

人们为何使用此工具

  • 快速将 JSON 示例转换为 SQL 表定义草稿。
  • 支持 PostgreSQL、MySQL、SQLite、SQL Server 和 Oracle。
  • 可作为检查列和数据类型的起点。

常见问题解答 (FAQ)

可以设计完整的数据库架构吗?

不可以。它根据一个 JSON 样例生成表草稿。请为实际应用补充键、约束、索引、关系和迁移。

指南 · 数据 · 约 3 分钟

UUID 指南:v4 与 v7 的区别,以及用 UUID 作数据库主键

550e8400-e29b-41d4-a716-446655440000 这样的字符串随处可见,用来标识订单、文件和 API 请求。了解 UUID 是如何生成的,以及该选择哪个版本。

UUID(通用唯一识别码)是一个 128 位的标识符,任何人无需询问中央服务器就能生成不会冲突的 ID。微软称之为 GUID。现行标准是 2024 年发布的 RFC 9562。

UUID 的结构、各版本的区别、为什么实际上不会碰撞,以及为什么作为主键 UUID v7 正逐渐取代 v4。
阅读指南 →
用 AI 自己做

用 AI 亲手打造这个工具

想要自己的版本?把下面的任务提示词粘贴到 AI 聊天中,或将技能文件保存到 AI 编程助手。其中包含我们开发此工具时整理的功能、边界情况和测试用例。

提示词和技能以英文提供,AI 工具在任何语言环境下都能很好地理解。

AI 任务提示词

直接粘贴到 Claude、ChatGPT、Gemini 等 AI 聊天中即可。

You are an experienced full-stack web developer. Build a web tool called "JSON DDL 生成器" that meets the requirements below.

## Goal

Build a tool that generates database CREATE TABLE statements from a JSON sample.

## Core features

- Choose MySQL, PostgreSQL, SQL Server or Oracle
- Infer column types from values
- Choose a primary key
- Option to map nested objects and arrays to child tables or JSON columns
- Copy result

## Inputs

- A JSON object or array of objects
- Database, table name, primary key

## Outputs

- CREATE TABLE SQL
- Reason for each inferred type

## Edge cases and handling rules

- Pick the widest type across rows (int + decimal → DECIMAL)
- Infer date/time types from ISO 8601 strings
- Allow NULL where null values appear
- Respect each database's identifier quoting and reserved words

## Implementation requirements

- Build it as a single page (HTML, CSS, JavaScript) that runs entirely in the browser, and never send the user's input to a server.
- Make the UI responsive and easy to use on mobile; label every input and keep everything keyboard accessible.
- Add a Copy button for results and show clear, friendly error messages for invalid input.
- Keep the core logic in functions separate from the UI so it can be unit-tested.

## Definition of done (test cases)

- {"id":1,"price":9.9,"createdAt":"2026-10-28T09:00:00Z"} gives integer, decimal and timestamp types
- PostgreSQL output uses double-quoted identifiers
- PRIMARY KEY appears when a key is chosen

First outline your implementation plan in at most five lines, then write the complete code, and finally explain how to check the test cases above.

技能 (SKILL.md)

在 Claude Code 等 AI 编程助手中保存为 .claude/skills/build-json-ddl-generator/SKILL.md,以后开发或修改此工具时可重复使用。

---
name: build-json-ddl-generator
description: Use when building or changing a JSON DDL 生成器 tool. Build a tool that generates database CREATE TABLE statements from a JSON sample.
---

# Build: JSON DDL 生成器

## Goal

Build a tool that generates database CREATE TABLE statements from a JSON sample.

## Workflow

1. Review the required features, inputs and outputs below and ask about anything missing first.
2. Implement the core logic as pure functions separate from the UI.
3. Check the logic against the test cases in the verification list.
4. Build a responsive UI with an input form, a result area and a Copy button.
5. Reproduce each edge case listed under Rules and refine the error messages.

## Core features

- Choose MySQL, PostgreSQL, SQL Server or Oracle
- Infer column types from values
- Choose a primary key
- Option to map nested objects and arrays to child tables or JSON columns
- Copy result

## Inputs

- A JSON object or array of objects
- Database, table name, primary key

## Outputs

- CREATE TABLE SQL
- Reason for each inferred type

## Rules

- Pick the widest type across rows (int + decimal → DECIMAL)
- Infer date/time types from ISO 8601 strings
- Allow NULL where null values appear
- Respect each database's identifier quoting and reserved words
- Build it as a single page (HTML, CSS, JavaScript) that runs entirely in the browser, and never send the user's input to a server.

## Verification

- [ ] {"id":1,"price":9.9,"createdAt":"2026-10-28T09:00:00Z"} gives integer, decimal and timestamp types
- [ ] PostgreSQL output uses double-quoted identifiers
- [ ] PRIMARY KEY appears when a key is chosen

交给 AI 时的小技巧

  • 在第一行写明技术栈(如 React、Vue 或纯 HTML),生成的代码会更贴合你的项目。
  • 在接受代码前,请让 AI 运行列出的测试用例并展示结果。
  • 不要把真实密码、客户数据或 API 密钥粘贴到提示词中,请用示例值代替。