Base64 to SQL Converter
Decode Base64-encoded strings to SQL queries instantly. Supports standard and URL-safe Base64, auto-formats SQL output, and handles UTF-8.
About
Base64 encoding is the standard method for transmitting binary or text data through channels that only support ASCII. Database migration scripts, API payloads, and CI/CD pipeline artifacts frequently store SQL statements as Base64 strings. Decoding these manually with command-line tools introduces risk: incorrect character encoding (especially with UTF-8 multi-byte sequences like Γ± or ΓΌ) silently corrupts your queries. A malformed INSERT statement can write garbage to production tables. This tool decodes both standard (RFC 4648 Β§4) and URL-safe (RFC 4648 Β§5) Base64, handles missing padding characters, and applies proper UTF-8 decoding via the TextDecoder API. The optional SQL formatter identifies clause boundaries and indents subqueries for readability.
Limitations: this tool does not validate SQL syntax or execute queries. It performs a faithful byte-level decode and presents the result. If the Base64 input encodes binary data (not text), the output will appear as garbled characters. For inputs exceeding 5 MB, performance may degrade in older browsers. Pro tip: if your Base64 string originates from a URL query parameter, it is likely URL-safe encoded - the tool auto-detects and handles the - and _ character substitutions.
Formulas
Base64 encoding converts every group of 3 bytes (24 bits) into 4 ASCII characters selected from an alphabet of 64 symbols. The encoded length is therefore predictable:
Where Lbytes = original byte count of the SQL string. The = padding character fills incomplete groups. URL-safe Base64 substitutes + β - and / β _, and may omit padding. The decode reverses this mapping:
Where normalize strips whitespace, restores URL-safe substitutions, and re-pads to a multiple of 4. Each Base64 character maps to a 6-bit value (since 26 = 64). The alphabet index is: A - Z = 0 - 25, a - z = 26 - 51, 0 - 9 = 52 - 61, + = 62, / = 63.
Reference Data
| SQL Keyword | Category | Standard | Formatting Rule Applied |
|---|---|---|---|
| SELECT | DQL | SQL-92 | Newline before, no indent |
| FROM | Clause | SQL-92 | Newline before, indent 1 level |
| WHERE | Clause | SQL-92 | Newline before, indent 1 level |
| AND / OR | Logical | SQL-92 | Newline before, indent 2 levels |
| JOIN / LEFT JOIN | Clause | SQL-92 | Newline before, indent 1 level |
| ON | Condition | SQL-92 | Newline before, indent 2 levels |
| INSERT INTO | DML | SQL-92 | Newline before, no indent |
| VALUES | Clause | SQL-92 | Newline before, indent 1 level |
| UPDATE | DML | SQL-92 | Newline before, no indent |
| SET | Clause | SQL-92 | Newline before, indent 1 level |
| DELETE FROM | DML | SQL-92 | Newline before, no indent |
| CREATE TABLE | DDL | SQL-92 | Newline before, no indent |
| ALTER TABLE | DDL | SQL-92 | Newline before, no indent |
| DROP TABLE | DDL | SQL-92 | Newline before, no indent |
| GROUP BY | Clause | SQL-92 | Newline before, indent 1 level |
| ORDER BY | Clause | SQL-92 | Newline before, indent 1 level |
| HAVING | Clause | SQL-92 | Newline before, indent 1 level |
| LIMIT | Clause | MySQL/PG | Newline before, indent 1 level |
| OFFSET | Clause | MySQL/PG | Newline before, indent 1 level |
| UNION | Set Op | SQL-92 | Newline before and after, no indent |
| WITH (CTE) | DQL | SQL:1999 | Newline before, no indent |
| BEGIN / COMMIT | TCL | SQL-92 | Newline before, no indent |
| CASE | Expression | SQL-92 | Newline before, indent 1 level |
| WHEN / THEN | Expression | SQL-92 | Newline before, indent 2 levels |
| END | Expression | SQL-92 | Newline before, matches CASE indent |