$catdatabase-schema-sql-builder.md
Database Schema & SQL Builder
Design normalized database schemas, write optimized SQL queries, and generate migration scripts.
Best
gpt-4o
Good
claude-sonnet-4, gemini-2.5-pro
Limited
claude-haiku, gpt-4o-mini
Updated
2026-05-22
workflow
You are a database architect. Design a production-ready database schema.
Use Case: {{useCase}} Core Entities: {{entities}} Database Type: {{databaseType || "PostgreSQL"}} Key Queries: {{queries || "CRUD operations, search, listing"}} Performance Requirements: {{performance || "Standard workload"}}
Schema Design
1. Entity Relationship Overview
[Entity] 1---* [Entity] : [relationship description]
[Entity] *---* [Entity] : [through join table]
...
2. Table Definitions
Table: [entity_name]
| Column | Type | Constraints | Default | Index | Notes |
|---|---|---|---|---|---|
| id | UUID | PK, NOT NULL | gen_random_uuid() | PK | Primary key |
| [field] | [type] | [constraints] | [default] | [index type] | [notes] |
| created_at | TIMESTAMPTZ | NOT NULL | NOW() | ||
| updated_at | TIMESTAMPTZ | NOT NULL | NOW() |
sqlCREATE TABLE [entity_name] ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), ... ); CREATE INDEX idx_[entity]_[field] ON [entity_name]([field]);
3. Relationships
| Parent | Child | Type | Foreign Key | ON DELETE |
|---|---|---|---|---|
| [table] | [table] | 1:N | [column] | CASCADE/SET NULL/RESTRICT |
| [table] | [table] | N:M | [join table] | CASCADE |
4. Migration Scripts
Migration 001: Initial Schema
sql-- Up [CREATE statements] -- Down [DROP statements]
Migration 002: [Description]
sql-- Up [ALTER statements] -- Down [ROLLBACK statements]
5. Optimized Queries
List [Entity] with Pagination
sqlSELECT * FROM [entity] WHERE [conditions] ORDER BY [field] [ASC/DESC] LIMIT $1 OFFSET $2;
Search [Entity]
sqlSELECT * FROM [entity] WHERE [text_field] ILIKE '%' || $1 || '%' OR [text_field] ILIKE '%' || $1 || '%' ORDER BY [relevance_field] DESC; -- Add full-text search index for production: -- CREATE INDEX idx_[entity]_fts ON [entity] USING GIN(to_tsvector('english', [field]));
Aggregation Query (Dashboard)
sqlSELECT DATE_TRUNC('[period]', created_at) AS period, COUNT(*) AS total, COUNT(DISTINCT [column]) AS unique_count, AVG([numeric_field]) AS average FROM [entity] WHERE created_at > NOW() - INTERVAL '[interval]' GROUP BY period ORDER BY period DESC;
6. Performance Notes
- Expected Data Size: [rows/month, total size]
- Index Strategy: Which columns need B-tree, GIN, or partial indexes
- Query Patterns: Read-heavy, write-heavy, or mixed
- Partitioning Recommendation: If applicable
- Connection Pooling: Recommended pool size
7. Normalization Level
- Current: [3NF, Star Schema, etc.]
- Denormalization Candidates: Fields that could be cached for performance
Output with code blocks for all SQL, | table | for column definitions, bold for table names, and --- for migration separators.
variables
^Enter
guide
how to use
- Open the Database Schema & SQL Builder workflow in your AI chat interface.
- Replace the variables in [brackets] with your specific inputs.
- For best results, use gpt-4o as the target model.
- Review the generated output and iterate by refining your inputs.
- Save your final result and share it with your team.
best use cases
- Quickly generate development-specific content with structured prompts.
- Standardize development workflows across your team using a shared template.
- Onboard new team members with a repeatable development process.
- Automate sql tasks with AI-powered development workflows.
- Automate database tasks with AI-powered development workflows.
- Automate schema-design tasks with AI-powered development workflows.
examples
- Use Database Schema & SQL Builder to create a sql project from scratch.
- Adapt Database Schema & SQL Builder for a different development domain with custom variables.
- Combine Database Schema & SQL Builder with other workflows in the development category for a complete pipeline.
- Run Database Schema & SQL Builder with multiple AI models to compare output quality.
- Schedule Database Schema & SQL Builder as a recurring development task.
variations
- Simplified version: remove optional variables for faster results.
- Advanced version: add custom validation steps after generation.
- Batch version: run Database Schema & SQL Builder on multiple inputs sequentially.
- sql-focused variant: emphasize sql best practices in the prompt.
- database-focused variant: emphasize database best practices in the prompt.
common mistakes
- Skipping variable customization — always replace [bracketed] placeholders.
- Using the wrong AI model tier for complex outputs.
- Not iterating on the first result — refinement improves quality significantly.
- Ignoring sql best practices when customizing the prompt.
- Using gpt-4o outside its optimal use case for this workflow.
related
same category
Code Review & Refactoring Assistant
Review code for bugs, performance issues, security vulnerabilities, and refactoring opportunities.
Full-Stack CRUD API Generator
Generate complete CRUD API endpoints with database schema, validation, error handling, and frontend integration code.
React Component Generator
Generate production-ready React components with TypeScript, Tailwind, and proper prop typing.
trending
ChatGPT Conversational Tutor
Learn any subject through adaptive Socratic dialogue with ChatGPT, tailored to your knowledge level and learning style.
ChatGPT GPT Builder Configurator
Design custom GPTs for ChatGPT with tailored instructions, knowledge files, conversation starters, and capabilities.
ChatGPT Prompt Library Manager
Design, organize, and optimize a reusable library of ChatGPT prompts for consistent output across projects and teams.
$ echo "contribute.sh"