Skip to content

Menu

Migration SQL Generator

Generate ALTER TABLE migration SQL

Runs entirely in your browserDatabaseFree, no sign-up
Loading tool

01What is Migration SQL Generator?

Hand-writing ALTER TABLE statements for three databases means remembering three sets of syntax, and the rollback usually gets skipped. This builder takes a list of operations and writes both the migration and a rollback section under it. Each row has a type: Add Column, Drop Column, Rename Column, Modify Column, Add Index, Drop Index, Add Constraint or Drop Constraint. You fill in a table and a column, and extra boxes appear where they matter. Those cover data type, a nullable checkbox, a default, a new name, an index name and a CHECK expression. If you leave the type empty it uses VARCHAR(255). For an index, the column box takes a comma-separated list. Index names default to idx_table_column and constraint names to ck_table_column. Names that are reserved words or not plain lowercase, like order, user or Status, are quoted. PostgreSQL and SQLite get double quotes and MySQL gets backticks, as each database's identifier rules expect. Defaults are handled with care too. Numbers, TRUE, FALSE, NULL, CURRENT_TIMESTAMP, function calls like now() and already-quoted strings pass through. Anything else becomes a string literal with single quotes doubled. The Dialect switch changes the statements. MySQL gets MODIFY COLUMN and DROP INDEX ... ON table. PostgreSQL gets ALTER COLUMN ... TYPE plus SET or DROP NOT NULL and SET DEFAULT. SQLite's ALTER TABLE cannot change a column or add or drop a constraint, according to its own docs. So for those rows you get a comment with the table rebuild steps instead of SQL that would fail. A quick example. In PostgreSQL, adding status to users as VARCHAR(20) with default active and nullable unchecked gives ALTER TABLE users ADD COLUMN status VARCHAR(20) DEFAULT 'active' NOT NULL. The rollback below it is ALTER TABLE users DROP COLUMN status. Rollbacks run in reverse order. Added columns and indexes are dropped, renames are swapped back and added constraints are removed. Dropped columns, dropped indexes and modified columns get a TODO comment, because the tool never saw the old definition. No rollback can bring back data from a dropped column. A few more limits. The tool does not check that your data type exists in the chosen dialect. It also does not warn about version needs, such as RENAME COLUMN in MySQL 8.0 or SQLite 3.25. The SQL is built in the page from what you type, and the tool never opens a connection to your database.

Backend developers and DBAs who keep schema changes as plain SQL files and want matching up and down scripts for PostgreSQL, MySQL or SQLite. The tool runs entirely in your browser, so your data never leaves your device.

02How to use Migration SQL Generator

  1. Choose PostgreSQL, MySQL or SQLite in Dialect.
  2. Click Add Operation for each change and pick its kind in the Type dropdown.
  3. Fill in table and column, then the extra fields that appear: data type, nullable, default, new name, index name or check expression.
  4. Remove a row you do not need with its trash icon.
  5. Read the Migration SQL panel, including the Rollback section, then click Copy SQL.

03Worked examples

Input: PostgreSQL, Add Column: table users, column status, type VARCHAR(20), default active, not nullable
Result: ALTER TABLE users ADD COLUMN status VARCHAR(20) DEFAULT 'active' NOT NULL; -- Rollback ALTER TABLE users DROP COLUMN status;
A bare word default is wrapped as a string literal.
Input: MySQL, Add Index: table order, column created_at
Result: CREATE INDEX idx_order_created_at ON `order` (created_at); -- Rollback DROP INDEX idx_order_created_at ON `order`;
order is a reserved word, so it gets backticks; MySQL's DROP INDEX also needs ON table.
Input: PostgreSQL, Modify Column: users.age, type INTEGER, nullable
Result: ALTER TABLE users ALTER COLUMN age TYPE INTEGER; ALTER TABLE users ALTER COLUMN age DROP NOT NULL; -- Rollback -- TODO: reverse modify_column on users (previous definition unknown)
The old type isn't known, so the rollback is left as a TODO.
Input: PostgreSQL, Drop Column: table user, column Legacy Flag
Result: ALTER TABLE "user" DROP COLUMN "Legacy Flag"; -- Rollback -- TODO: ALTER TABLE "user" ADD COLUMN "Legacy Flag" <original type>; (the dropped data cannot be restored)
user is reserved and Legacy Flag has a capital and a space, so both are quoted.
Input: PostgreSQL, Drop Column: table user, column Legacy Flag
Result: ALTER TABLE "user" DROP COLUMN "Legacy Flag"; -- Rollback -- TODO: ALTER TABLE "user" ADD COLUMN "Legacy Flag" <original type>; (the dropped data cannot be restored)
user is reserved and Legacy Flag has a capital and a space, so both are quoted.
Input: MySQL, Add Index: table orders, column tenant_id, created_at
Result: CREATE INDEX idx_orders_tenant_id_created_at ON orders (tenant_id, created_at); -- Rollback DROP INDEX idx_orders_tenant_id_created_at ON orders;
A comma-separated column list makes a composite index. Header comments trimmed.

04Common use cases

  • Writing a plain SQL migration file for Flyway or golang-migrate, with the down script ready next to it.
  • Drafting a hotfix that adds a nullable phone column to users, plus the statement that removes it again.
  • Adding a composite index such as tenant_id, created_at with a consistent idx_ naming scheme for a slow-query ticket.
  • Adding a CHECK constraint like price >= 0 to an existing PostgreSQL or MySQL table.
  • Preparing a script a DBA can review line by line when the ORM's generated migration is not acceptable.
  • Finding out quickly that a change needs a table rebuild on SQLite before you promise it in a sprint.

05Tips

  • A default of active becomes 'active'. Type 0, TRUE, now() or CURRENT_TIMESTAMP when you want a number, boolean or expression instead.
  • Adding a NOT NULL column with no default fails on a table that already has rows. Tick nullable or give it a default.
  • MySQL RENAME COLUMN needs MySQL 8.0 or later, and SQLite needs 3.25 or later.
  • Fill the TODO lines in the rollback before you merge. They mark places where the old definition was unknown.
  • Back up the table before a Drop Column. The rollback can recreate the column, never its data.

06Related concepts

Schema migrations, ALTER TABLE, Database rollback, DDL, Database indexes.

Frequently Asked Questions

What is Migration SQL Generator?

Migration SQL Generator is a free, browser-based developer tool on AIDToolStack. Generate ALTER TABLE migration SQL It requires no installation or sign-up and works entirely in your browser.

Is Migration SQL Generator free to use?

Yes. No sign-up, no fees and no usage cap.

Does Migration SQL Generator store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe