Query Sanitizer
Strip comments, SET statements, and trailing semicolons from SQL.

SQL Query Sanitizer — Strip Comments & Clean Up a SQL Query

The Query Sanitizer strips comments, SET statements, and trailing semicolons from a SQL query before you share it or run it somewhere else. It's built for developers who need to remove comments from SQL query before pasting it into documentation, a support ticket, or a different environment where leftover session settings or comments could cause confusion or errors.

⚡ Key Takeaways

  • Strips comments, SET statements, and trailing semicolons in one click.
  • Never changes the actual query logic — cleanup only.
  • Removing a SET statement can change behavior if the query depends on it.
  • Keep a commented reference copy if the removed context matters for later maintenance.

What, Who, When & Why

What it's forStrips comments, SET statements, and trailing semicolons from a SQL query.
Who it's forDevelopers sharing or relocating a query to a different environment, ticket, or piece of documentation.
When to use itBefore pasting a query into a public forum, support ticket, or a different database environment.
Why it's neededLeftover comments can expose internal context, and session-specific SET statements may not apply — or may error — elsewhere.
Best way to use itKeep a separate copy of the original query if its comments contain important context, since sanitizing removes them permanently.

How to Use the Query Sanitizer

  1. Paste your SQL query into the Input box.
  2. Click Sanitize to strip out comments, SET statements, and trailing semicolons.
  3. Review the cleaned query in the Output box.
  4. Click Copy to grab the sanitized query.

Example

Given a query with a leading comment, a SET statement, and a trailing semicolon:

SET NOCOUNT ON;
-- fetch active users
SELECT id, name FROM users WHERE status = 'active'; -- only active accounts

Sanitizing removes the SET statement, both comments, and the trailing semicolon, leaving a clean, portable query:

SELECT id, name FROM users WHERE status = 'active'

Key Features

  • Strips single-line and inline SQL comments.
  • Removes SET statements that set session-specific variables.
  • Removes trailing semicolons that can cause issues in some execution contexts.
  • Leaves the actual query logic untouched — only cleanup, no logic changes.
  • Instant, one-click sanitizing with no manual find-and-replace needed.

Practical Use Cases

  • Sharing queries externally: remove internal comments before pasting a query into a public forum, ticket, or documentation.
  • Cross-environment portability: strip session-specific SET statements that may not apply — or may error out — in a different database environment.
  • Preparing queries for embedding: remove trailing semicolons before embedding a query as a string in application code, where an extra semicolon can sometimes cause a syntax error.
  • Documentation: present a clean, comment-free query example in a wiki or README without exposing internal notes.
  • Code review prep: strip out debugging comments left in a query before submitting it for review.

Tips for Best Results

  • If your comments contain important context (like why a filter exists), copy that context into a separate note before sanitizing, since it will be removed.
  • Run the sanitizer before formatting with the SQL Formatter, so the beautified output doesn't include leftover comment artifacts.
  • Double-check queries that rely on a SET statement for correct behavior (like a specific isolation level) — removing it may change how the query executes in a new environment.

Related Terminology

SQL comments (starting with -- for single-line, or wrapped in /* */ for block comments) are notes for humans that databases ignore during execution. SET statements configure session-level variables or options — like isolation level, date formats, or numeric precision — and are often environment-specific, meaning they may not be relevant, or may even cause errors, when a query is run somewhere else.

Important Considerations

Sanitizing removes comments entirely, including any that document important context about the query's purpose or assumptions — consider keeping a separate, commented reference copy if that context matters for future maintenance. Similarly, if a SET statement is functionally required for your query to behave correctly (not just a leftover from a specific session), removing it could change the query's results in its new environment, so review what's being stripped before running the sanitized version somewhere critical.

Related Tools

Once sanitized, format your query with the SQL Formatter for readability, or get a plain-English breakdown with the SQL Query Explainer. For building the query from a boilerplate starting point, see the SQL Query Templates.

Frequently Asked Questions

How do I remove comments from a SQL query?

Paste your query into the Input box and click Sanitize — comments are stripped automatically, along with SET statements and trailing semicolons.

Does sanitizing change what the query actually does?

No, it only removes comments, SET statements, and trailing semicolons — the core query logic (SELECT, FROM, WHERE, JOIN, etc.) is left completely unchanged.

Will removing a SET statement break my query?

It can, if the query depends on that session setting to behave correctly — review what's being removed before running the sanitized version in a new environment.

Can I get my removed comments back afterward?

No, sanitizing doesn't keep a record of what was removed — keep a copy of the original query if you might need the comments again later.