Create beginner Works with: Any AI

SQL Query Documentation and Naming Standards

Before after

Make queries readable and maintainable.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Rate this prompt

Loading ratings…

Make my SQL readable and maintainable. Team and tools: [TEAM_AND_TOOLS]. Dialect: [SQL_DIALECT]. Problems with current queries: [PROBLEMS]. An example query to improve: [PASTE_QUERY].

Return:
BEFORE: the original query, with annotations in square brackets at each problem ([unclear alias], [nested subquery that could be a CTE], [implicit join], [magic number], [no comment on business logic], [select star], [inconsistent case]).
AFTER: the rewritten query that follows the standards, with a header comment block (purpose, owner, inputs, outputs, assumptions, change log) and inline comments only where logic is not obvious.
STANDARDS: a one-page style guide of ten enforceable rules covering naming of tables, columns, aliases, and CTEs; formatting and indentation; keyword case; join style; handling of dates and time zones; null handling; comments; and file organization in version control.
REVIEW: a checklist for reviewing query changes, and tools to automate formatting and linting for my dialect.
CHANGES: a list of what was changed and why, so the reviewer can confirm the results are identical, plus a query to compare outputs of the old and new versions.

Optimize for the next reader. Keep rules that a linter can enforce separate from taste.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

Related prompts