Free Online SQL Regex Replace Tool
Batch rename tables, columns, and refactor SQL queries using regular expressions. Preview every change, undo mistakes, and clean up legacy SQL scripts — all in your browser, no signup needed.
Try SQL Regex Replace Now
Paste your SQL, enter a regex pattern, and see every match before you commit. Free, private, instant.
Open Regex Replace ToolBatch Table Renames
Rename every reference to a table across FROM, JOIN, and subquery clauses with one regex pattern.
Scoped Matching
Limit regex to table names, column names, comments, or the full SQL. No accidental replacements in wrong contexts.
Full Preview
See every match highlighted with old → new values before committing. Verify all changes at a glance.
Undo Support
Every operation is tracked. Undo the last replace or reset to the original SQL at any time.
Why Use Regex for SQL Refactoring?
Manually renaming tables or columns across a large SQL script is tedious and error-prone. A single users reference might appear in SELECT lists, WHERE clauses, JOIN conditions, and subqueries — and missing one breaks the query. Regex replace finds them all.
The key advantage of regex over plain find-and-replace is precision. You can use word boundaries (\b) to avoid partial matches, character classes for pattern matching, and backreferences to carry parts of the original text into the replacement.
Common Use Cases
- Add table prefixes or schemas — e.g., rename
userstoapp_schema.usersacross an entire migration script - Strip deprecated column prefixes — remove legacy
tbl_orcol_prefixes from column names - Standardize naming conventions — convert snake_case to camelCase or PascalCase
- Clean up comments — remove TODO markers, old author notes, or debug comments from production SQL
- Bulk parameterize values — replace hardcoded IDs or dates with bind variables
Example: Rename All Customer Columns
Start with a query that has verbose customer_ prefixes on every column:
Set regex to customer_, replacement to cust_, scope to Entire SQL. Result:
Notice customers (the table name) was not changed — the regex customer_ followed by an underscore only matched column names. For even tighter control, use scope "Column Names" to restrict matching to identifiers only.
Regex Flags Explained
The tool exposes three regex flags as toggles:
- g (global) — Replace all matches, not just the first. Always on by default.
- i (case-insensitive) — Treat uppercase and lowercase as identical. Useful when SQL has mixed casing.
- m (multiline) — Makes
^and$match line boundaries, not just the full string. Essential for comment cleaning.
Frequently Asked Questions
Paste your SQL into the tool, set the scope to 'Table Names', enter a regex pattern like (users|orders|products), and a replacement like new_$1. The tool matches table references across FROM, JOIN, INTO, and UPDATE clauses. Preview shows each match before you apply the rename.
Yes. Choose from four scopes: Entire SQL (default), Table Names (targets table references in FROM/JOIN/INTO clauses), Column Names (targets column identifiers), and Comments (targets -- and /* */ style comments). This prevents accidental replacements in the wrong context.
Yes. Click 'Preview Changes' to see every match highlighted with old → new values before committing. You can also undo the last operation or reset back to the original SQL at any point.
Yes. Every operation is tracked in a history stack, so you can undo the last replacement or reset back to the original query at any point - including after a batch rename across a large script.
The tool uses JavaScript's RegExp engine supporting character classes, groups with backreferences ($1, $2...), alternation (|), quantifiers (*, +, ?), word boundaries (\b), and flags: g (global), i (case-insensitive), m (multiline).
Yes. The tool is completely free with no signup, no credit card, and no usage limits. All regex matching runs in your browser — your SQL never leaves your machine. Use it as many times as you need for any size of SQL script.
Yes. Matching happens locally in the browser, so there is no upload step and no size limit - mysqldump output, migration scripts and multi-thousand-line .sql files can be pasted in directly. For very large files, strip comments first with the Comments scope and then run your structural renames.