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.
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. No signup, no credit card, no limits. Everything runs client-side — your SQL never leaves your browser.
Yes. Every operation is tracked in a history stack. Undo the last replacement or reset back to the original query at any time.
Four scopes: Entire SQL (default), Table Names, Column Names, and Comments. Scoping prevents accidental replacements in unintended contexts.
Yes. JavaScript regex supports lookaheads ((?=...), (?!...)), capturing groups with backreferences ($1, $2...), and all standard quantifiers and character classes.