Database Schema as SQL DDL

D

Daniel Okoye

@daniel-okoye

·

Generate complete SQL DDL from data model descriptions.

67 copies0 forks
Share this prompt:
Generate complete PostgreSQL DDL for this data model:

Data Model Description:
{{data_model}}

Relationships:
{{relationships}}

Constraints:
{{constraints}}

Output complete DDL:

```sql
-- ============================================
-- Schema: {{schema_name}}
-- Generated: YYYY-MM-DD
-- ============================================

-- Enable required extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- ============================================
-- TABLES
-- ============================================

CREATE TABLE table_name (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    -- columns
    CONSTRAINT constraint_name CHECK (condition)
);

-- ============================================
-- INDEXES
-- ============================================

CREATE INDEX idx_table_column ON table_name(column);
CREATE INDEX idx_table_composite ON table_name(col1, col2);

-- ============================================
-- FOREIGN KEYS
-- ============================================

ALTER TABLE child_table
    ADD CONSTRAINT fk_child_parent
    FOREIGN KEY (parent_id) REFERENCES parent_table(id)
    ON DELETE CASCADE;

-- ============================================
-- TRIGGERS
-- ============================================

CREATE TRIGGER update_timestamp
    BEFORE UPDATE ON table_name
    FOR EACH ROW
    EXECUTE FUNCTION update_updated_at();
```

Include:
- All tables with proper data types
- Primary and foreign keys
- Indexes for query patterns
- Check constraints
- Trigger functions

Details

Category

Coding

Use Cases

Schema generation automationData model implementationDatabase migration creation

Works Best With

claude-opus-4.5gpt-5.2gemini-2.0-flash
Created Updated Shared

Related Prompts

Create your own prompt vault and start sharing