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 Tool

Batch 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

Example: Rename All Customer Columns

Start with a query that has verbose customer_ prefixes on every column:

SELECT customer_id, customer_name, customer_email, customer_phone FROM customers WHERE customer_status = 'active'

Set regex to customer_, replacement to cust_, scope to Entire SQL. Result:

SELECT cust_id, cust_name, cust_email, cust_phone FROM customers WHERE cust_status = 'active'

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:

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.