Claude Skills Guide

Best Way to Feed Claude Code a Large SQL Schema

When working with large SQL databases, getting Claude Code to understand and work with your schema efficiently requires strategy. Here’s how to maximize Claude’s ability to analyze, design, and generate SQL for complex database structures.

Why Schema Presentation Matters

Claude Code processes text contextually. A 5,000-line SQL dump presented all at once often leads to fragmented understanding. The solution is strategic chunking and clear organization that plays to Claude’s pattern recognition strengths.

The File Reference Strategy

The most effective approach uses Claude Code’s file reading capability. Instead of pasting schema into chat, reference SQL files directly:

Read the schema from models/schema.sql and analyze the table relationships.

This approach offers several advantages: Claude reads the complete file without truncation, maintains proper formatting, and can re-read specific sections as needed during the conversation.

For projects with multiple schema files, organize them logically:

/database
  /schemas
    users.sql
    orders.sql
    products.sql
  /migrations

Then reference them precisely:

Analyze the user and order schemas and suggest indexes for query optimization.

The @ Mention Technique

Claude Code supports referencing files with the @ symbol directly in your prompt. This works exceptionally well for SQL schemas:

@database/schema.sql Create a query that joins users with orders and includes product details.

For very large schemas spanning multiple files, mention each file explicitly:

@schemas/core_tables.sql @schemas/lookup_tables.sql @schemas/audit_tables.sql 
Design an ERD-friendly relationship diagram and identify potential normalization issues.

Schema Summary Technique for Massive Databases

For databases with hundreds of tables, provide a summary first, then dive into specifics. Create a schema overview file:

-- Schema Overview
-- ==============
-- Core Tables: users, accounts, sessions
-- Transaction Tables: orders, payments, refunds
-- Reference Tables: categories, countries, currencies

-- Primary Keys: All tables use UUID for id column
-- Foreign Keys: All relationships use cascade delete
-- Timestamps: All tables include created_at, updated_at

Then instruct Claude:

Using the overview in schema_summary.md, focus on the transaction tables 
and generate migration scripts for adding order history tracking.

Using Claude Code Skills for SQL

Several Claude Code skills enhance SQL schema work. The xlsx skill helps when you need to import schema from spreadsheet exports:

Use the xlsx skill to read the database schema from schema_export.xlsx 
and convert it to proper CREATE TABLE statements.

The docx skill assists when documenting schemas:

Use the docx skill to create a schema documentation file from the 
table definitions we've analyzed.

Prompt Engineering for Schema Tasks

Structure your prompts for specific outcomes:

For Schema Analysis:

Analyze @schemas/ecommerce.sql and identify:
1. Tables missing foreign key constraints
2. Potential N+1 query issues
3. Tables that would benefit from composite indexes

For SQL Generation:

Based on the user and order schemas in @database/schema.sql, generate:
1. A view for order totals by customer
2. A stored procedure for monthly revenue calculation
3. Triggers for updated_at timestamp management

For Migration Planning:

Review @schemas/legacy.sql and @schemas/modern.sql and create a 
migration strategy document with rollback procedures.

Handling Schema Without Files

When you must paste schema directly, use formatting strategically. Instead of:

users table has id, name, email, password, created_at. orders table has id, user_id, total, status, created_at.

Use structured SQL CREATE statements:

CREATE TABLE users (
    id UUID PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    password_hash VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE orders (
    id UUID PRIMARY KEY,
    user_id UUID REFERENCES users(id),
    total DECIMAL(10,2) NOT NULL,
    status VARCHAR(50) DEFAULT 'pending',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Then prompt:

Create an index strategy for these tables assuming most queries 
filter by user_id and filter by date ranges on created_at.

The Context Window Advantage

Claude Code’s large context window handles substantial schemas, but optimization improves results. For databases with 100+ tables:

  1. Group related tables: Separate core business logic from audit/logging tables
  2. Prioritize active schema: Focus on tables currently in development
  3. Use views strategically: If a schema has many legacy tables, create views that present a cleaner interface

Practical Example: E-Commerce Schema

Here’s a complete workflow for a large e-commerce database:

Step 1: Provide context

I have a PostgreSQL e-commerce database with ~50 tables covering:
- User management (auth, profiles, addresses)
- Product catalog (items, categories, inventory)
- Order processing (orders, line items, payments)
- Shipping (shipments, carriers, tracking)

Step 2: Reference the schema

@db/schema/users.sql @db/schema/products.sql @db/schema/orders.sql @db/schema/shipping.sql

Step 3: Specify the task

Design a query that retrieves all orders from the past 30 days, 
including customer details, order items with product info, 
payment status, and latest shipment tracking.

This approach gives Claude the context, the data, and the specific task—all elements needed for accurate SQL generation.

Key Takeaways

  1. Reference files over pasting — Use @ mentions or file paths for large schemas
  2. Chunk strategically — Group related tables rather than dumping everything at once
  3. Provide schema overviews — For massive databases, create summary documents first
  4. Structure prompts specifically — Clear, scoped requests yield better SQL
  5. Use skills complementarily — The xlsx and docx skills handle schema import/export

Master these techniques, and Claude Code becomes significantly more effective at understanding your database structure and generating precise, optimized SQL for any task.

Built by theluckystrike — More at zovo.one