ALTER TABLE DROP COLUMN rollback leaves column – what is the documented behavior in Firebird 4.0?
0 reputation · 28 Aug 2024, 10:42 UTC
0 reputation · 28 Aug 2024, 10:42 UTC
To determine whether a transaction that performs ALTER TABLE DROP COLUMN can be fully rolled back in Firebird 4.0, restoring the original schema state without leaving residual objects.
Firebird 2.5+ supports transactional DDL, but documentation notes that dropping a column is not fully reversible. The behavior appears to vary between releases (2.5, 3.0, 4.0). No explicit statement confirms that a rollback will always remove the dropped column in 4.0.
ROLLBACK after ALTER TABLE DROP COLUMN in Firebird 4.0 always revert the schema to its pre‑change state?In Firebird 4.0 ALTER TABLE DROP COLUMN is transactional DDL. A ROLLBACK will attempt to revert the metadata changes, but the operation is documented as not fully reversible. You should not rely on rollback to restore the dropped column with its data.
Confirmed fact: Firebird 4.0 with ODS 13+ runs DDL inside the current transaction and logs metadata changes for rollback. The official documentation treats DROP COLUMN as having limited reversibility compared with ADD COLUMN.
Likely explanation, not a guarantee: after ROLLBACK the column definition can become visible again in RDB$RELATION_FIELDS and SHOW TABLE, because the metadata log is undone. Physical data pages for the dropped column are discarded during the DROP and are not recovered by rollback. If the metadata does reappear it is empty / NULL-filled, not the original values.
Transactional DDL was improved in Firebird 4.0, but DROP COLUMN remains a special case. The documentation consistently warns that dropping a column is not fully reversible and that data loss can be permanent even if the schema appears to roll back. There is no version-specific note in Firebird 4.0 that makes DROP COLUMN fully reversible.
SET TRANSACTION;
SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME = 'TEST_TABLE' AND RDB$FIELD_NAME = 'TEST_COL';
ALTER TABLE TEST_TABLE DROP COLUMN TEST_COL;
ROLLBACK;
SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME = 'TEST_TABLE' AND RDB$FIELD_NAME = 'TEST_COL';
SHOW TABLE TEST_TABLE;
Also inspect dependent objects:
SELECT RDB$INDEX_NAME FROM RDB$INDICES WHERE RDB$RELATION_NAME = 'TEST_TABLE';
SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$RELATION_NAME = 'TEST_TABLE';
There is no built-in cleanup command beyond ROLLBACK. Full restoration requires manual recreation from saved DDL:
Assumptions used here: Firebird 4.0, ODS 13+, default transactional DDL enabled, explicit transaction with autocommit off. Behavior is version and ODS dependent.
One diagnostic detail that changes the recommendation: is the database on ODS 13+ and was the ALTER executed in an explicit transaction with autocommit disabled? If autocommit was on, the DDL was committed immediately and ROLLBACK has no effect.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.