Menu

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.

Obfuscation Studio Free
Ready
SQL Query 0 lines • 0 chars
Obfuscated Output 0 lines • 0 chars
Obfuscation Options
All processing runs in your browser. Your query is never uploaded. Real tables, columns, schemas, functions, and bind parameters are never renamed — only CTE names and aliases the query itself declares.
Complete Guide to SQL Query Obfuscation

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.

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

  1. 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.
  2. Split into statements. Top-level ; characters (not inside parentheses) divide the script into independently-scoped statements.
  3. Find candidates, per statement. CTE names, explicit AS aliases (with CAST/TRY_CAST/CONVERT type-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.
  4. Rename consistently. Every occurrence of a candidate name within its own statement is replaced with a short generated name.
  5. 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 is not validated: that the query actually executes correctly against your database, or returns the same results. Always run both the original and obfuscated query against a test database and compare before relying on the output.

What's Safe vs Unsafe to Rename

ConstructRenamed?Reason
CTE name (WITH name AS (...))YesIntroduced by the query, scoped to its own statement
Explicit table/column alias (AS alias)YesIntroduced by the query, unambiguous to detect
Implicit alias (table alias, no AS)Opt-in, off by defaultSafe in principle, but detection relies on a keyword list that can't cover every dialect
Real table, view, or schema nameNeverExists in your database independent of this query
Real column nameNeverExists in the table's schema; renaming it breaks the query
Function or stored procedure nameNeverDefined in the database or engine, not by this query
Bind parameters (:id, @id, $1, ?)NeverYour application code binds values to these by exact name or position
Type name in CAST(expr AS type)NeverSpecifically detected and excluded — it's a type, not an alias
Contents of string literals and quoted identifiersNeverPassed 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?
A SQL query obfuscator rewrites a query so the names it introduces — CTEs and table/column aliases — are harder to read, while leaving every real schema object (tables, columns, schemas, functions) and bind parameter completely untouched, so the query still runs against the exact same database.
Why doesn't it rename table and column names?
Table and column names aren't local to the query the way a variable is local to a function — they're real objects that already exist in your database. Renaming them in the query text without renaming them in the schema would simply make the query fail. This tool only ever renames names the query itself creates: CTEs and declared aliases.
Why no string-literal encoding, unlike your other obfuscators?
The code obfuscators on this site bundle a small decoder function into the same file that gets compiled or interpreted, so a string can be decoded at runtime. A SQL query has nowhere to put that decoder — it's sent to the database engine as-is, and there's no portable, dialect-independent function available everywhere to decode a value inline. Simulating one would require deploying a custom stored function first (syntax differs across MySQL/Postgres/SQL Server/Oracle), add real per-query overhead, and still not hide anything meaningful, since SQL literals are rarely the sensitive part of a query — the logic and structure are.
Will this break bind parameters like :id, @id, or ?
No — by design, bind parameters (:name, @name, $1, ?) are never touched under any option, since your application code binds values to these by exact name or position. Renaming one would silently break the connection between your query and your code.
Does it handle multiple statements in one script safely?
Yes. A CTE or alias only exists for the statement that declares it, so this tool splits a script on top-level semicolons and renames within each statement independently. A later statement's genuine reference to a same-named real table is never mistaken for an earlier statement's CTE or alias.
Is my SQL uploaded to your server?
No. The obfuscator runs entirely as JavaScript inside your browser. Your query text never leaves your device.
What's the difference between explicit and implicit alias renaming?
An explicit alias uses the AS keyword (FROM customers AS c) and is unambiguous to detect. An implicit alias has no AS (FROM customers c) and is distinguished from a real table name only by position and by not matching a large list of SQL keywords — a dialect-specific keyword this tool doesn't know about could in rare cases be misread as an alias. Explicit-alias and CTE renaming are on by default; implicit-alias renaming is off by default so you can review a query before enabling it.
Does it work with CAST(expr AS type)?
Yes — the tool specifically recognizes CAST, TRY_CAST, SAFE_CAST, and CONVERT and skips the AS inside them, since that AS introduces a data type, not an alias.
Does it support MySQL, Postgres, SQL Server, Oracle, and SQLite?
The tokenizer recognizes all common identifier-quoting styles (double quotes, backticks, square brackets) and leaves whichever one your query uses completely untouched. One MySQL-specific detail is not handled: '#' line comments are intentionally left alone, since '#' and '##' also prefix temporary-table names in SQL Server — stick to -- and /* */ comments for comment removal to work.
Does it understand subqueries and derived tables?
Yes. A derived table's alias, e.g. FROM (SELECT ...) AS x, is detected the same way as a plain table alias, and the subquery's own FROM/JOIN clauses are scanned the same way recursively, so nested aliases are handled correctly without treating keywords inside the subquery as ending the outer clause.
Will it rename a function name that happens to match an alias?
No — as a safety net, any name that's used as a function call anywhere in the statement (immediately followed by a parenthesis) is excluded from renaming entirely, even if it also looked like a CTE or alias elsewhere.
Can obfuscated SQL be reversed?
It's a mild deterrent on readability, not encryption — anyone can still run the query and see what data it returns. Never rely on this for protecting sensitive logic from someone who can already execute the query.
Can I use this commercially?
Yes. You may obfuscate any query you own or have rights to modify and use the output however you like.
How is the output validated?
This tool cannot run a real SQL parser in the browser, so it performs a structural validation pass: it re-tokenizes the output and checks that parentheses/brackets are balanced and that every string literal and quoted identifier is correctly terminated. This is not a substitute for running the query against your actual database, which you should always do before relying on the output.
Does it change what the query returns?
It shouldn't — only self-declared names are renamed, consistently everywhere they're referenced, and real schema objects are left untouched. Still, always diff and test the obfuscated query against your database before using it anywhere that matters.

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.