$ recombobulate _
home / tips / use-claude-to-write-sql-views-and-stored-procedures
0

Use Claude to Write SQL Views and Stored Procedures

bagwaa @bagwaa · Mar 26, 2026 · Workflows
use-claude-to-write-sql-views-and-stored-procedures

Writing SQL views and stored procedures by hand is tedious and error-prone. Just describe what you need and Claude will generate the full statement, handle the joins, and add comments explaining each section.

Write a SQL view called user_sales_summary that joins users, orders, 
and order_items. Return: user_id, email, total_orders, total_revenue, 
and last_order_date per user. Use MySQL syntax.

Claude handles complex aggregations, window functions, and conditional logic without you needing to remember the exact syntax. For Laravel, ask it to wrap the result in a migration:

Write a Laravel migration that creates or replaces a view called 
active_subscriptions showing all subscriptions where status = 'active' 
and expires_at > NOW(). Include the down() method to drop the view.

For stored procedures with parameters:

Write a MySQL stored procedure called calculate_user_tier that takes a 
user_id parameter. Based on their total spend in the last 90 days, 
return 'bronze', 'silver', or 'gold'. Add inline comments explaining the tiers.

Claude will generate the DELIMITER blocks, parameter declarations, and proper BEGIN...END structure — the parts that are easy to get wrong.

Your DBA hat is optional when Claude's writing the SQL.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago