⚙️ Settings
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 for | Strips comments, SET statements, and trailing semicolons from a SQL query. |
|---|---|
| Who it's for | Developers sharing or relocating a query to a different environment, ticket, or piece of documentation. |
| When to use it | Before pasting a query into a public forum, support ticket, or a different database environment. |
| Why it's needed | Leftover comments can expose internal context, and session-specific SET statements may not apply — or may error — elsewhere. |
| Best way to use it | Keep a separate copy of the original query if its comments contain important context, since sanitizing removes them permanently. |
How to Use the Query Sanitizer
- Paste your SQL query into the Input box.
- Click Sanitize to strip out comments, SET statements, and trailing semicolons.
- Review the cleaned query in the Output box.
- 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.
WITH recent_orders AS (
SELECT
customer_id,
order_id,
order_date,
total_amount
FROM orders
WHERE order_date >= DATEADD(day, -30, GETDATE())
)
SELECT
customer_id,
COUNT(order_id) AS order_count,
SUM(total_amount) AS total_spent
FROM recent_orders
GROUP BY customer_id
ORDER BY total_spent DESC;
WITH RECURSIVE employee_hierarchy AS (
-- Anchor: top-level rows (no manager)
SELECT
employee_id,
manager_id,
employee_name,
1 AS level
FROM employees
WHERE manager_id IS NULL
UNION ALL
-- Recursive: join children to their parent's result
SELECT
e.employee_id,
e.manager_id,
e.employee_name,
eh.level + 1
FROM employees e
INNER JOIN employee_hierarchy eh
ON e.manager_id = eh.employee_id
)
SELECT *
FROM employee_hierarchy
ORDER BY level, employee_name;
-- Note: SQL Server / Oracle: drop the RECURSIVE keyword (just WITH employee_hierarchy AS (...))
SELECT
o.order_id,
c.customer_name,
o.order_date,
p.product_name,
oi.quantity
FROM orders o
INNER JOIN customers c
ON o.customer_id = c.customer_id
LEFT JOIN order_items oi
ON o.order_id = oi.order_id
LEFT JOIN products p
ON oi.product_id = p.product_id
WHERE o.order_date >= '2026-01-01'
ORDER BY o.order_date DESC;
SELECT
DATE_TRUNC('month', order_date) AS order_month, -- PostgreSQL
-- FORMAT(order_date, 'yyyy-MM') AS order_month, -- SQL Server
-- DATE_FORMAT(order_date, '%Y-%m') AS order_month, -- MySQL
COUNT(*) AS order_count,
SUM(total_amount) AS revenue
FROM orders
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY order_month;
SELECT
customer_id,
order_id,
order_date,
total_amount,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY order_date DESC
) AS order_rank,
SUM(total_amount) OVER (
PARTITION BY customer_id
ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_total
FROM orders;
CREATE PROCEDURE GetCustomerOrders
@CustomerId INT,
@StartDate DATE = NULL,
@EndDate DATE = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT
order_id,
order_date,
total_amount
FROM orders
WHERE customer_id = @CustomerId
AND (@StartDate IS NULL OR order_date >= @StartDate)
AND (@EndDate IS NULL OR order_date <= @EndDate)
ORDER BY order_date DESC;
END;
-- Call it: EXEC GetCustomerOrders @CustomerId = 101, @StartDate = '2026-01-01';
MERGE INTO customers AS target
USING staging_customers AS source
ON target.customer_id = source.customer_id
WHEN MATCHED THEN
UPDATE SET
target.customer_name = source.customer_name,
target.email = source.email,
target.updated_at = GETDATE()
WHEN NOT MATCHED THEN
INSERT (customer_id, customer_name, email, created_at)
VALUES (source.customer_id, source.customer_name, source.email, GETDATE());
#FACC15
rgb(250, 204, 21)
rgb(98%, 80%, 8%)
hsl(46, 96%, 53%)
hsv(46, 92%, 98%)
cmyk(0%, 18%, 92%, 2%)
Tools for analysts, developers & QA engineers
33 free, browser-based utilities — text and list tools, SQL helpers, converters, and small productivity apps. Everything runs locally; nothing you type or paste is ever uploaded.
For Analysts
Clean lists, build SQL fragments, and reshape data without opening a spreadsheet.
For Developers
Format SQL, convert data formats, and handle everyday text and encoding tasks.
For QA Engineers
Generate test data, compare text output, and sanitize queries before sharing them.