SQL Query Obfuscator
Renames CTE names and declared table/column aliases — never your real tables, columns, schemas, or bind parameters — entirely in your browser. Every output is re-checked for structural integrity before it's shown to you.
SQL query obfuscation is fundamentally different from obfuscating a programming language. In C#, Kotlin, or JavaScript, almost everything in a function body is local and safe to rename. In SQL, almost everything is a reference to a real object that already exists in your database — a table, a column, a schema, a stored function — and renaming any of those in the query text without also renaming them in the database would simply break the query.
So this tool is deliberately narrow: it renames only the names a query introduces itself — CTE names (WITH name AS (...)) and table/column aliases (AS alias, or the implicit form) — and leaves every real schema object and every bind parameter (:id, @id, $1, ?) exactly as written.
Table of Contents
What is SQL Query Obfuscation?
At its core, SQL obfuscation obscures a query's business meaning — what a CTE or alias is called often tells a reader what the query is for (e.g. high_risk_customers, unpaid_invoices_90d) more than the schema itself does. Renaming those self-declared names to meaningless short identifiers removes that signal while the query continues to run against the exact same tables and columns, unchanged.
This is a much smaller scope than a code obfuscator, by necessity — and that's the point. A tool that tried to rename table or column names would produce queries that simply fail against a real database, which would make it actively harmful rather than merely limited.
Techniques Used by This Tool
CTE Name Renaming
Names introduced in a WITH name AS (...) clause (including multiple comma-separated CTEs and WITH RECURSIVE) are renamed consistently everywhere they're referenced later in that same statement — never across a ; into an unrelated later statement.
Alias Renaming
Table and column aliases introduced with AS are renamed by default; the no-AS implicit form is available as an opt-in, since telling an implicit alias apart from the start of the next clause relies on a (large but not exhaustive) SQL keyword list.
Per-Statement Scoping
A script with multiple statements is split on top-level semicolons (ignoring any ; that's inside a string, comment, or nested inside parentheses), and each statement is analyzed and renamed independently — so a CTE or alias from one statement can never bleed into, or be confused with, a real table reference in a different statement.
Comment Removal
Strips -- line comments and /* */ block comments (non-nested, matching standard SQL — unlike some programming languages, SQL block comments don't nest), without touching comment-like text inside strings or quoted identifiers.
How the Tool Works
- Tokenize. A hand-written tokenizer splits the query into identifiers, keywords, string literals, quoted identifiers (double-quote, backtick, or bracket style), numbers, bind parameters, and comments.
- Split into statements. Top-level
;characters (not inside parentheses) divide the script into independently-scoped statements. - Find candidates, per statement. CTE names, explicit
ASaliases (withCAST/TRY_CAST/CONVERTtype-specifications explicitly excluded), and — if enabled — implicit aliases are detected using position and a comprehensive SQL keyword list, with any name also used as a function call excluded as a final safety net. - Rename consistently. Every occurrence of a candidate name within its own statement is replaced with a short generated name.
- Reconstruct and validate. Tokens are re-emitted in order, and the output is re-tokenized to confirm parentheses/brackets are balanced and literals are properly terminated.
Output Validation
A browser cannot run a real SQL parser against your specific database dialect, so this tool performs a structural validation pass only: it re-tokenizes the obfuscated result and confirms parentheses/brackets are balanced and every string literal and quoted identifier is correctly terminated.
What's Safe vs Unsafe to Rename
| Construct | Renamed? | Reason |
|---|---|---|
CTE name (WITH name AS (...)) | Yes | Introduced by the query, scoped to its own statement |
Explicit table/column alias (AS alias) | Yes | Introduced by the query, unambiguous to detect |
Implicit alias (table alias, no AS) | Opt-in, off by default | Safe in principle, but detection relies on a keyword list that can't cover every dialect |
| Real table, view, or schema name | Never | Exists in your database independent of this query |
| Real column name | Never | Exists in the table's schema; renaming it breaks the query |
| Function or stored procedure name | Never | Defined in the database or engine, not by this query |
Bind parameters (:id, @id, $1, ?) | Never | Your application code binds values to these by exact name or position |
Type name in CAST(expr AS type) | Never | Specifically detected and excluded — it's a type, not an alias |
| Contents of string literals and quoted identifiers | Never | Passed through byte-for-byte, regardless of quoting style |
Use Cases
Sharing a Query Externally
Post a query to a forum, support ticket, or issue tracker without the alias/CTE names revealing what the business logic is actually about.
Internal Reports & Dashboards
Obscure the intent of a proprietary reporting query embedded in a BI tool or internal doc, while keeping it fully runnable against the live schema.
SQL Coursework & Interview Exercises
Obscure a reference query's structure while leaving the underlying table/column names (which students must already know) untouched.
Tidying Noisy Queries
Strip comments and excess whitespace from a generated or legacy query before sharing it, independent of whether you rename anything.
Limitations & Legal
- Not encryption. This is a readability deterrent, not security. Anyone who can execute the query sees exactly what it returns regardless of alias names.
- No string-literal encoding. Unlike this site's code obfuscators, SQL has no portable place to put a runtime decoder — see the FAQ for why this is a deliberate omission, not an oversight.
- Implicit-alias detection is keyword-dependent. It relies on a large SQL keyword list; an unusual or very new dialect-specific keyword immediately after a table reference could in rare cases be misread. Review output before using it, especially with implicit aliases enabled.
#MySQL line comments aren't stripped. SQL Server also uses#/##for temp-table names, so handling it generically risked corrupting unrelated dialects. Use--or/* */comments for comment removal to apply.- Named window clauses and complex DDL (stored procedure bodies, triggers) are outside this tool's focus, which is DML queries (SELECT/INSERT/UPDATE/DELETE).
- Legal. Only obfuscate queries you own or have rights to modify and share.
Related Obfuscators
Frequently Asked Questions
What is a SQL query obfuscator?
Why doesn't it rename table and column names?
Why no string-literal encoding, unlike your other obfuscators?
Will this break bind parameters like :id, @id, or ?
Does it handle multiple statements in one script safely?
Is my SQL uploaded to your server?
What's the difference between explicit and implicit alias renaming?
Does it work with CAST(expr AS type)?
Does it support MySQL, Postgres, SQL Server, Oracle, and SQLite?
Does it understand subqueries and derived tables?
Will it rename a function name that happens to match an alias?
Can obfuscated SQL be reversed?
Can I use this commercially?
How is the output validated?
Does it change what the query returns?
Conclusion
SQL obfuscation can't — and shouldn't try to — work like code obfuscation. This tool stays inside the one boundary that actually matters: never touch anything the query didn't invent itself. CTE names and aliases get obscured; your tables, columns, functions, and bind-parameter contract stay exactly as they were, so the query keeps running against your real database.