// sqlite · sql behavior

legacy_alter_table

Use the pre 3.25 ALTER TABLE RENAME behavior that leaves most schema references untouched.

Predeterminado
0 (off)
Range
0, 1
Restart needed
No
Default checked on
SQLite 3.5x

Lo que hace

Off by default, a rename rewrites every reference to the table anywhere in the schema. With it on, only the name in the CREATE TABLE statement and in associated CREATE INDEX and CREATE TRIGGER statements changes; references inside trigger bodies, views, the table's own CHECK constraints and partial-index WHERE clauses keep the old name. New applications should leave it off.

Valor predeterminado

0 (off). Off (a stock SQLite 3.5x build). For compatibility with older virtual table implementations SQLite toggles it on only inside their xRename call.

Check the current value

PRAGMA legacy_alter_table;

SELECT * FROM pragma_legacy_alter_table;   -- table-valued form, usable in queries

Change it

PRAGMA legacy_alter_table = ON;   -- this connection only

No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When to change it

Running old code that depends on the pre 3.25 rename behavior, for example migration scripts that rename a table and patch references by hand.

What can go wrong

With it on, a rename leaves views, triggers and partial indexes pointing at the old name, so the next use of those objects fails or keeps resolving to another table that owns the old name, and nothing warns about the dangling references.

Questions about legacy_alter_table

What is the default value of legacy_alter_table in SQLite?

0 (off). Off (a stock SQLite 3.5x build). For compatibility with older virtual table implementations SQLite toggles it on only inside their xRename call.

Does changing legacy_alter_table require a restart?

No. No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When should I change legacy_alter_table?

Running old code that depends on the pre 3.25 rename behavior, for example migration scripts that rename a table and patch references by hand.

Back to all SQLite settings, or check the SQLite manual for every option.

// one client for every engine

Check legacy_alter_table on your own server

SQLly runs the query above against SQLite and the other engines in this reference, from one desktop app on macOS, Windows and Linux.

Texto y datos de esta página: CC BY 4.0, con atribución a SQLly (sqlly.app). Código y fragmentos SQL: MIT. Detalles de la licencia