ChatGPT Prompt to Generate a Database Schema
Designing a database schema is a fundamental step in any software project. A well-thought-out schema ensures data consistency, optimizes query performance, and facilitates long-term maintenance. Yet this task requires expertise in relational modeling, normalization, and choosing suitable data types. ChatGPT can significantly accelerate this process by generating a structured schema from a functional description of your project. By providing the business context, main entities, and expected relationships, you obtain in seconds a complete SQL schema with primary keys, foreign keys, indexes, and constraints. The AI can also suggest optimizations such as targeted denormalization for read-heavy cases, or recommend proven patterns like soft delete or table polymorphism. Whether you are working on a SaaS application, an e-commerce site, or an internal management system, ChatGPT adapts the schema to your chosen DBMS — PostgreSQL, MySQL, SQLite, or SQL Server — while adhering to each engine's conventions and native types.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
You are a senior database architect with 15 years of experience in relational modeling. I am developing an application for [PROJECT_DESCRIPTION]. Here are the main business entities: [LIST_OF_ENTITIES]. The business rules are: [BUSINESS_RULES]. The target DBMS is [PostgreSQL/MySQL/SQLite]. Generate a complete database schema in SQL with: 1) All tables with their columns, appropriate data types, and comments, 2) Primary keys (UUID or auto-increment depending on context), 3) Foreign keys with appropriate ON DELETE and ON UPDATE constraints, 4) Indexes on frequently searched or filtered columns, 5) Relevant CHECK and UNIQUE constraints, 6) Audit columns (created_at, updated_at, deleted_at if soft delete), 7) Junction tables for many-to-many relationships. After the SQL, provide a text-format relationship diagram and a list of design decisions with their justifications.
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Why this prompt works
This prompt works because it assigns a precise expert role to the AI, which steers the quality of responses to a professional level. The numbered list of expected deliverables forces a comprehensive and structured answer, avoiding common oversights like indexes or constraints. Finally, asking for justification of design choices pushes the AI to reason about each decision rather than applying generic patterns.
Use Cases
Variants
Expected Output
You will obtain a complete, executable SQL script containing all CREATE TABLE statements with native data types for the chosen DBMS, relational constraints, indexes, and audit columns. The result will also include a text diagram of relationships between entities and a document of architectural decisions explaining normalization, typing, and indexing choices.
Frequently Asked Questions
Can ChatGPT generate a schema for any DBMS?
Yes, ChatGPT understands the SQL syntax of PostgreSQL, MySQL, SQLite, SQL Server, and Oracle. It adapts data types (e.g., SERIAL in PostgreSQL vs AUTO_INCREMENT in MySQL), built-in functions, and engine-specific extensions. Always specify the target DBMS in your prompt to get a script that runs immediately without modifications.
Does the generated schema comply with normal forms?
By default, ChatGPT generates schemas in third normal form (3NF), eliminating redundancies and transitive dependencies. If your use case requires denormalization for performance reasons (dashboards, reports), specify it in the prompt. The AI can then suggest a hybrid schema with denormalized columns or materialized views for read-heavy queries.
How do I integrate the generated schema into an existing project with an ORM?
You can ask ChatGPT to generate the schema directly in your ORM's format: Prisma models, TypeORM entities, Django models, Drizzle schemas, or Alembic migrations. Simply add to the prompt: "Generate the schema in [ORM NAME] format" and the AI will output the corresponding code with decorators, annotations, and configurations specific to the chosen tool.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt Guide📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Generate Mocks and Fixtures for Your Automated Tests
A prompt to automatically generate realistic mocks, stubs and data fixtures adapted to your test framework and use cases.
Automatically Generate Unit Tests with AI
Automatically generate an exhaustive unit test suite covering nominal cases, edge cases, and error cases for any source code.
Create a Python Automation Script
Create a professional Python automation script with CLI configuration, structured logging, error handling, and tests.
Analyze and Optimize Algorithmic Complexity
Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.