This one covers the fundamentals of writing stored procedures, functions, and triggers across PostgreSQL and MySQL. You get examples for scalar functions, multi-step procedures with error handling, and trigger implementations for audit trails and data validation. The quick start shows a straightforward calculation function, and the reference guides walk through progressively complex scenarios. It's practical if you're moving business logic into the database layer or need reusable routines that multiple applications can call. The coverage is solid on the basics, though you'll want to supplement with database-specific docs for advanced features like cursor handling or dynamic SQL.

skills.sh installs
457
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill stored-procedures --agent claude-code

Installs into .claude/skills of the current project.

Files

Stored Procedures & Functions

Table of Contents

Overview

Implement stored procedures, functions, and triggers for business logic, data validation, and performance optimization. Covers procedure design, error handling, and performance considerations.

When to Use

  • Business logic encapsulation
  • Complex multi-step operations
  • Data validation and constraints
  • Audit trail maintenance
  • Performance optimization
  • Code reusability across applications
  • Trigger-based automation

Quick Start

PostgreSQL - Scalar Function:

-- Create function returning single value
CREATE OR REPLACE FUNCTION calculate_order_total(
  p_subtotal DECIMAL,
  p_tax_rate DECIMAL,
  p_shipping DECIMAL
)
RETURNS DECIMAL AS $$
BEGIN
  RETURN ROUND((p_subtotal * (1 + p_tax_rate) + p_shipping)::NUMERIC, 2);
END;
$$ LANGUAGE plpgsql IMMUTABLE;

-- Use in queries
SELECT id, subtotal, calculate_order_total(subtotal, 0.08, 10) as total
FROM orders;

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Backend & APIs, AI & Agent Building, Databases
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1manutej avatarpytestmanutej/luxor-claude-marketplaceAdvanced Python unit testing framework for customer support tech enablement, covering FastAPI, SQLAlchemy, PostgreSQL, async operations, mocking, fixtures, para457skills.sh installs
2bobmatnyc avatarwordpress-advanced-architecturebobmatnyc/claude-mpm-skillsAdvanced WordPress development with REST API endpoints, WP-CLI commands, performance optimization, and caching strategies for scalable applications.455skills.sh installs
3hoodini avatargoogle-workspace-clihoodini/ai-agents-skillsInteract with all Google Workspace APIs via the gws CLI. Use when managing Drive files, sending/reading Gmail, creating Calendar events, reading/writing Sheets/455skills.sh installs
4mrgoonie avatarshopifymrgoonie/claudekit-skillsBuild Shopify applications, extensions, and themes using GraphQL/REST APIs, Shopify CLI, Polaris UI components, and Liquid templating. Capabilities include app 454skills.sh installs
5openai avataropenai-knowledgeopenai/openai-agents-pythonUse when working with the OpenAI API (Responses API) or OpenAI platform features (tools, streaming, Realtime API, auth, models, rate limits, MCP) and you need a453skills.sh installs
6mblode avatardefine-architecturemblode/agent-skillsGenerates folder structures, module contracts, middleware pipelines, and frontend/backend boundaries for TypeScript full-stack applications, and finds domain-in448skills.sh installs